{smcl}
{txt}{sf}{ul off}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}E:\Github\Bolivia\00_replication_files\log-files/1_Data_part1_initialsetup.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}25 Jan 2022, 20:53:28
{txt}
{com}. 
. timer on 2
{txt}
{com}. 
. *-----------------*
. * 1. Computo data *
. *-----------------*
.         import excel "data/inputs/1_Bolivia_data_computo.xlsx", ///
>                 sheet("2.RecepcionSobres") firstrow clear
{res}{txt}
{com}. 
.         keep if ElecActa == "Presidente y Vicepresidente"
{txt}(33,585 observations deleted)

{com}.         keep ComputoDate CC FPV MTS UCS MAS F PDC MNR Blancos Nulos PANBOL  ///
>                 Pais - Reci NumMesa CodVer Inscritos
{txt}
{com}. 
.         rename ComputoDate computo_date
{res}{txt}
{com}. 
.         foreach x of varlist CC - Nulos {c -(}
{txt}  2{com}.                 replace `x' = 0 if `x' == .
{txt}  3{com}.         {c )-}
{txt}(556 real changes made)
(19,341 real changes made)
(13,725 real changes made)
(18,101 real changes made)
(13 real changes made)
(3,694 real changes made)
(676 real changes made)
(16,485 real changes made)
(14,322 real changes made)
(7,377 real changes made)
(942 real changes made)

{com}. 
.         compress
  {txt}variable {bf}MTS{sf} was {bf}{res}int{sf}{txt} now {bf}{res}byte{sf}
{txt}  (34,555 bytes saved)

{com}.         tempfile computo_data
{txt}
{com}.         save `computo_data'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_000001.tmp saved

{com}. 
. *---------------------------------------------------------------------*
. * 2a. TREP transmission time stamps, using EstadoActa == "Registrada" *
. *---------------------------------------------------------------------*
.         import excel "data/inputs/1_Bolivia_data_trep.xlsx", ///
>                 sheet("Data") firstrow clear
{res}{txt}
{com}. 
.         keep if EstadoActa == "Registrada" &  ///
>                 ElecActa == "Presidente y Vicepresidente"
{txt}(102,082 observations deleted)

{com}. 
.         * These fifteen were transmitted from outside the app
.         replace UltTransmisionDate = FechaRegistroenLog if ///
>                 UltTransmisionDate == . & FechaRegistroenLog != .
{txt}(15 real changes made)

{com}. 
.         * There are duplicates at the mesa level, so we keep the one with the
.         * most recent date
.         bys NumMesa (UltTransmisionDate): gen t = _n
{txt}
{com}.         bys NumMesa: gen T = _N
{txt}
{com}.         keep if t == T
{txt}(344 observations deleted)

{com}.         drop t T
{txt}
{com}. 
.         * Following the OAS, we use the Cómputo vote totals even with the
.         * TREP time stamps, here we drop the TREP vote totals
.         keep Pais - EstadoActa UltTransmisionDate
{txt}
{com}. 
.         rename UltTransmisionDate trep_date_ulttrans
{res}{txt}
{com}. 
.         compress
  {txt}variable {bf}Circun{sf} was {bf}{res}str30{sf}{txt} now {bf}{res}str1{sf}
  {txt}variable {bf}EstadoActa{sf} was {bf}{res}str21{sf}{txt} now {bf}{res}str10{sf}
{txt}  (1,367,120 bytes saved)

{com}.         tempfile trep_fechas_ulttrans
{txt}
{com}.         save `trep_fechas_ulttrans'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_000002.tmp saved

{com}. 
. *---------------------------------------------------------------------*
. * 2b. TREP verification time stamps, using EstadoActa == "Verificada" *
. *---------------------------------------------------------------------*
.         import excel "data/inputs/1_Bolivia_data_trep.xlsx", ///
>                 sheet("Data") firstrow clear
{res}{txt}
{com}. 
.         keep if EstadoActa == "Verificada" &  ///
>                 ElecActa == "Presidente y Vicepresidente"
{txt}(103,559 observations deleted)

{com}. 
.         * There are duplicates at the mesa level, so we keep the one with the
.         * most recent date
.         bys NumMesa (VerificadorDate): gen t = _n
{txt}
{com}.         bys NumMesa: gen T = _N
{txt}
{com}.         keep if t == T
{txt}(1 observation deleted)

{com}.         drop t T
{txt}
{com}. 
.         * Following the OAS, we use the Cómputo vote totals even with the
.         * TREP time stamps, here we drop the TREP vote totals
.         keep Pais - EstadoActa VerificadorDate
{txt}
{com}. 
.         rename VerificadorDate trep_date_verificador
{res}{txt}
{com}. 
.         compress
  {txt}variable {bf}Circun{sf} was {bf}{res}str30{sf}{txt} now {bf}{res}str1{sf}
  {txt}variable {bf}EstadoActa{sf} was {bf}{res}str21{sf}{txt} now {bf}{res}str10{sf}
{txt}  (1,321,760 bytes saved)

{com}.         tempfile trep_fechas_verificadas
{txt}
{com}.         save `trep_fechas_verificadas'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_000003.tmp saved

{com}. 
. *----------------------------------------------------------------------------*
. * 3a. Merging TREP transmission time stamps (from 2a) to Computo vote totals *
. *----------------------------------------------------------------------------*
.         use `computo_data', clear
{txt}
{com}.         assert _N == 34555
{txt}
{com}. 
.         merge 1:1 NumMesa using `trep_fechas_ulttrans', ///
>                 keepusing(trep_date*)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}             377
{txt}{col 9}from master{col 30}{res}             377{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}          34,178{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         qui su _m if _m == 2
{txt}
{com}.         assert `r(sum)' == 0
{txt}
{com}.         drop _merge
{txt}
{com}. 
.         * Generating dummies to know which observations have a missing date
.         gen trep_missing_date_ulttrans = (trep_date_ulttrans == .)
{txt}
{com}.         qui su trep_missing_date_ulttrans if trep_missing_date_ulttrans == 1
{txt}
{com}.         assert `r(sum)' == 377
{txt}
{com}.         
.         compress
  {txt}variable {bf}trep_missing_date_ulttrans{sf} was {bf}{res}float{sf}{txt} now {bf}{res}byte{sf}
{txt}  (103,665 bytes saved)

{com}.         tempfile computo_data_3a
{txt}
{com}.         save `computo_data_3a'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_000004.tmp saved

{com}. 
. *----------------------------------------------------------------------------*
. * 3b. Merging TREP verification time stamps (from 2b) to Computo vote totals *
. *----------------------------------------------------------------------------*
.         use `computo_data', clear
{txt}
{com}.         assert _N == 34555
{txt}
{com}.         
.         merge 1:1 NumMesa using `trep_fechas_verificadas', ///
>                 keepusing(trep_date*)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}           1,511
{txt}{col 9}from master{col 30}{res}           1,511{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}          33,044{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         qui su _m if _m == 2
{txt}
{com}.         assert `r(sum)' == 0    
{txt}
{com}.         drop _merge
{txt}
{com}. 
.         * Generating dummys to know which observations have a missing date
.         gen trep_missing_date_verificador = (trep_date_verificador == .)
{txt}
{com}.         su trep_missing_date_verificador if trep_missing_date_verificador == 1

{txt}    Variable {c |}        Obs        Mean    Std. Dev.       Min        Max
{hline 13}{c +}{hline 57}
trep_missi~r {c |}{res}      1,511           1           0          1          1
{txt}
{com}.         assert `r(sum)' == 1511
{txt}
{com}.         
.         compress
  {txt}variable {bf}trep_missing_date_verificador{sf} was {bf}{res}float{sf}{txt} now {bf}{res}byte{sf}
{txt}  (103,665 bytes saved)

{com}.         tempfile computo_data_3b
{txt}
{com}.         save `computo_data_3b'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_000005.tmp saved

{com}. 
. *---------------------------------------------------------------------------*
. * 4. Generating three data sets with Cómputo vote totals and                       *
. *    TREP *verification* time stamps:                                                                       *
. * a) DROPPING the 1,511 observations that were excluded from part of        *
. *        the OAS analysis because they do not have EstadoActa == "Verificada".  *       
. *    Within identical time stamps, we sort observations randomly.                       *                          
. * b) KEEPING those 1,511 observations, and assigning them the maximum       *
. *        verification time stamp (following the OAS note that they are          *
. *        "late reporters"). Within identical time stamps, we sort observations  *
. *    randomly.                                                                                                                      *
. * c) The same as 4a, but using the same exact sort order as the OAS (per    *
. *        the replication data), rather than sorting randomly within                 *
. *    identical time stamps.                                                 *
. *---------------------------------------------------------------------------*
. * 5. Generating two data sets with Cómputo vote totals and                         *
. *    TREP *transmission* time stamps:                                       *
. * a) DROPPING the 377 observations with missing transmission time stamps    *
. * b) KEEPING those observations, and replacing the missing time stamps      *
. *    with the median transmission time in the municipality                  *
. *---------------------------------------------------------------------------*
.         foreach x in 4a 4b 4c 5a 5b {c -(}
{txt}  2{com}.                 * 4a. Verification date, dropping missings
.                 if "`x'"=="4a" {c -(}                
{txt}  3{com}.                         use `computo_data_3b', clear
{txt}  4{com}.                         drop if trep_missing_date_verificador == 1
{txt}  5{com}.                         local date_var = "trep_date_verificador"
{txt}  6{com}.                         local file = "computo_verificadortrepdate_nomissings"
{txt}  7{com}.                 {c )-}
{txt}  8{com}.         
.                 * 4b. Verification date, missings appended at the end
.                 else if "`x'"=="4b" {c -(}
{txt}  9{com}.                         use `computo_data_3b', clear
{txt} 10{com}.                         sum trep_date_verificador
{txt} 11{com}.                         local max = r(max)
{txt} 12{com}.                         replace trep_date_verificador = `max' if trep_date_verificador == .
{txt} 13{com}.                         local date_var = "trep_date_verificador"
{txt} 14{com}.                         local file = "computo_verificadortrepdate_missingsatthend"
{txt} 15{com}.                 {c )-}
{txt} 16{com}.                 
.                 * 4c. Verification date, dropping missings, OAS order
.                 else if "`x'"=="4c" {c -(}
{txt} 17{com}.                         use `computo_data_3b', clear
{txt} 18{com}.                         drop if trep_missing_date_verificador == 1
{txt} 19{com}.                         
.                         * Get OAS sort order
.                         preserve
{txt} 20{com}.                                 use "data/inputs/1_Bolivia_OAS_Nooruddin_replication_dataset.dta", clear
{txt} 21{com}.                                 keep cum_ps_natl_share num_mesa_trep verificador_date
{txt} 22{com}.                                 rename num_mesa_trep NumMesa
{txt} 23{com}.                                 renvars cum_ps_natl_share verificador_date, postfix(_OAS)
{txt} 24{com}.                                 tempfile OAS_Nooruddin_order
{txt} 25{com}.                                 save `OAS_Nooruddin_order'
{txt} 26{com}.                         restore
{txt} 27{com}. 
.                         merge 1:1 NumMesa using `OAS_Nooruddin_order'
{txt} 28{com}.                         drop if _m == 2
{txt} 29{com}.                         drop _merge
{txt} 30{com}.                         rename cum_ps_natl_share_OAS x /* Sort order within identical time stamps */
{txt} 31{com}. 
.                         local date_var = "verificador_date_OAS"
{txt} 32{com}.                         local file = "computo_verificadortrepdate_nomissings_oasorder"
{txt} 33{com}.                 {c )-}
{txt} 34{com}. 
.                 * 5a. Transmission date, dropping missings
.                 else if "`x'"=="5a" {c -(}
{txt} 35{com}.                         use `computo_data_3a', clear
{txt} 36{com}.                         drop if trep_missing_date_ulttrans == 1
{txt} 37{com}.                         local date_var = "trep_date_ulttrans"
{txt} 38{com}.                         local file = "computo_ulttranstrepdate_nomissings"
{txt} 39{com}.                 {c )-}
{txt} 40{com}.                 
.                 * 5b. Transmission date, missings at the municipio median
.                 else if "`x'"=="5b" {c -(}
{txt} 41{com}.                         use `computo_data_3a', clear
{txt} 42{com}.                         bys Pais Dep Prov Muni: egen median_date = median(trep_date_ulttrans)
{txt} 43{com}.                         replace trep_date_ulttrans = median_date if trep_missing_date == 1
{txt} 44{com}.                         drop median_date        
{txt} 45{com}.                         local date_var = "trep_date_ulttrans"
{txt} 46{com}.                         local file = "computo_ulttranstrepdate_missingsatmunmedian"
{txt} 47{com}.                 {c )-}
{txt} 48{com}. 
.                 * Within ties, sort randomly for all data sets except 4c.
.                 if "`x'"!="4c" {c -(}
{txt} 49{com}.                         gen x = runiform()
{txt} 50{com}.                 {c )-}
{txt} 51{com}. 
.                 * Measures that DO USE Blancos and Nulos (sorted)
.                 gen total_so = CC + FPV + MTS + UCS + MAS + F + PDC + MNR + PANBOL + ///
>                         Blancos + Nulos
{txt} 52{com}.                 *---*
.                 gen mshare_so = MAS / total_so
{txt} 53{com}.                 gen cshare_so = CC / total_so
{txt} 54{com}.                 sort `date_var' x
{txt} 55{com}.                 gen cumsumtotal_so = sum(total_so)
{txt} 56{com}.                 *---*
.                 egen maxcumsumtotal_so = max(cumsumtotal_so)
{txt} 57{com}.                 gen pcs_so = cumsumtotal_so / maxcumsumtotal_so /* Percentile of vote counted */
{txt} 58{com}.                 drop cumsumtotal_so maxcumsumtotal_so
{txt} 59{com}. 
.                 * Measures that DO NOT USE Blancos and Nulos (sorted)
.                 gen total_nbnn = CC + FPV + MTS + UCS + MAS + F + PDC + MNR + PANBOL
{txt} 60{com}.                 *---*
.                 gen mshare_nbnn_so = MAS / total_nbnn
{txt} 61{com}.                 gen cshare_nbnn_so = CC / total_nbnn
{txt} 62{com}.                 sort `date_var' x
{txt} 63{com}.                 drop x
{txt} 64{com}.                 gen cumsumtotal_nbnn = sum(total_nbnn)
{txt} 65{com}.                 *---*
.                 egen maxcumsumtotal_nbnn = max(cumsumtotal_nbnn)
{txt} 66{com}.                 gen pcs_nbnn_so = cumsumtotal_nbnn / maxcumsumtotal_nbnn 
{txt} 67{com}.                 drop cumsumtotal_nbnn maxcumsumtotal_nbnn
{txt} 68{com}.                 
.                 * There is one pair of recinctos (precincts) with identical names
.                 * in the same locality/municipality/province/department.
.                 * Here we change the name so as to distinguish them
.                 replace Reci = "Unidad Educativa Privada La Paz 1" if ///
>                         Reci == "Unidad Educativa Privada La Paz" ///
>                         & Muni == "Nuestra Señora de La Paz" ///
>                         & Prov == "Murillo" ///
>                         & Dep == "La Paz" ///
>                         & NumMesa>=22383 & NumMesa<=22386
{txt} 69{com}.                 replace Reci = "Unidad Educativa Privada La Paz 2" if ///
>                         Reci == "Unidad Educativa Privada La Paz" ///
>                         & Muni == "Nuestra Señora de La Paz" ///
>                         & Prov == "Murillo" ///
>                         & Dep == "La Paz" ///
>                         & NumMesa>22386 
{txt} 70{com}.                 
.                 * Save
.                 compress
{txt} 71{com}.                 sort Pais Dep Prov Muni Loc Reci
{txt} 72{com}.                 saveold "data/outputs//`file'.dta", ///
>                         replace
{txt} 73{com}.         {c )-}
{txt}(1,511 observations deleted)
(2 missing values generated)
(2 missing values generated)
(2 missing values generated)
(2 missing values generated)
(4 real changes made)
(4 real changes made)
  variable {bf}total_so{sf} was {bf}{res}float{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}total_nbnn{sf} was {bf}{res}float{sf}{txt} now {bf}{res}int{sf}
{txt}  (132,176 bytes saved)
(saving in Stata 13 format)
{p 0 6 2}
(FYI, {bf:saveold} has options
{bf:version(12)} and {bf:version(11)} that
write files in older Stata formats)
{p_end}
(note: file data/outputs//computo_verificadortrepdate_nomissings.dta not found)
file data/outputs//computo_verificadortrepdate_nomissings.dta saved

    Variable {c |}        Obs        Mean    Std. Dev.       Min        Max
{hline 13}{c +}{hline 57}
trep_date_~r {c |}{res}     33,044    1.89e+12    1.53e+07   1.89e+12   1.89e+12
{txt}(1,511 real changes made)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 real changes made)
(4 real changes made)
  variable {bf}total_so{sf} was {bf}{res}float{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}total_nbnn{sf} was {bf}{res}float{sf}{txt} now {bf}{res}int{sf}
{txt}  (138,220 bytes saved)
(saving in Stata 13 format)
{p 0 6 2}
(FYI, {bf:saveold} has options
{bf:version(12)} and {bf:version(11)} that
write files in older Stata formats)
{p_end}
(note: file data/outputs//computo_verificadortrepdate_missingsatthend.dta not found)
file data/outputs//computo_verificadortrepdate_missingsatthend.dta saved
(1,511 observations deleted)
{res}{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_000007.tmp saved
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}           1,511
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}           1,511{txt}  (_merge==2)

{col 5}matched{col 30}{res}          33,044{txt}  (_merge==3)
{col 5}{hline 41}
(1,511 observations deleted)
{res}{txt}(2 missing values generated)
(2 missing values generated)
(2 missing values generated)
(2 missing values generated)
(4 real changes made)
(4 real changes made)
  variable {bf}total_so{sf} was {bf}{res}float{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}total_nbnn{sf} was {bf}{res}float{sf}{txt} now {bf}{res}int{sf}
{txt}  (132,176 bytes saved)
(saving in Stata 13 format)
{p 0 6 2}
(FYI, {bf:saveold} has options
{bf:version(12)} and {bf:version(11)} that
write files in older Stata formats)
{p_end}
(note: file data/outputs//computo_verificadortrepdate_nomissings_oasorder.dta not found)
file data/outputs//computo_verificadortrepdate_nomissings_oasorder.dta saved
(377 observations deleted)
(2 missing values generated)
(2 missing values generated)
(2 missing values generated)
(2 missing values generated)
(4 real changes made)
(4 real changes made)
  variable {bf}total_so{sf} was {bf}{res}float{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}total_nbnn{sf} was {bf}{res}float{sf}{txt} now {bf}{res}int{sf}
{txt}  (136,712 bytes saved)
(saving in Stata 13 format)
{p 0 6 2}
(FYI, {bf:saveold} has options
{bf:version(12)} and {bf:version(11)} that
write files in older Stata formats)
{p_end}
(note: file data/outputs//computo_ulttranstrepdate_nomissings.dta not found)
file data/outputs//computo_ulttranstrepdate_nomissings.dta saved
(4 missing values generated)
(373 real changes made)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 real changes made)
(4 real changes made)
  variable {bf}total_so{sf} was {bf}{res}float{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}total_nbnn{sf} was {bf}{res}float{sf}{txt} now {bf}{res}int{sf}
{txt}  (138,220 bytes saved)
(saving in Stata 13 format)
{p 0 6 2}
(FYI, {bf:saveold} has options
{bf:version(12)} and {bf:version(11)} that
write files in older Stata formats)
{p_end}
(note: file data/outputs//computo_ulttranstrepdate_missingsatmunmedian.dta not found)
file data/outputs//computo_ulttranstrepdate_missingsatmunmedian.dta saved

{com}. 
. 
. *---------------------------------------------------*
. * 6. Adding covariates to two of the data sets          *
. *---------------------------------------------------*
.         do "codes/1_Data_part2_covariates.do"
{txt}
{com}. clear
{txt}
{com}. 
. cap program drop superclean_basic
{txt}
{com}. include "codes/auxiliary_programs/superclean_basic.ado"
{txt}
{com}. cap program drop superclean_basic
{txt}
{com}. program define superclean_basic
{txt}  1{com}.         syntax varlist(min=1)
{txt}  2{com}. 
.         foreach z of varlist `varlist' {c -(}
{txt}  3{com}.                 replace `z' = subinstr(`z', "Ã", "A", .)
{txt}  4{com}.                 replace `z'= subinstr(`z',"Ã","A",.)
{txt}  5{com}.                 replace `z'= subinstr(`z',"Ã","A",.)
{txt}  6{com}.                 replace `z'= subinstr(`z',"Ã","A",.)
{txt}  7{com}.                 replace `z'= subinstr(`z',"Ã","A",.)
{txt}  8{com}.                 replace `z' = subinstr(`z', "Ã", "E", .)
{txt}  9{com}.                 replace `z' = subinstr(`z', "Ã", "I", .)
{txt} 10{com}.                 replace `z' = subinstr(`z', "Ã", "U", .)
{txt} 11{com}.                 replace `z' = subinstr(`z', "Ã", "O", .)
{txt} 12{com}.                 replace `z' = subinstr(`z', "Ã", "N", .)
{txt} 13{com}.                 replace `z' = subinstr(`z', "NÂ°", "nº", .)
{txt} 14{com}.                 replace `z' = subinstr(`z', "NÂº", "nº", .)  
{txt} 15{com}.                 replace `z' = subinstr(`z', `"""', "", .)
{txt} 16{com}.                 replace `z' = subinstr(`z', "Â", "", .)
{txt} 17{com}.                 replace `z' = subinstr(`z', "â", "", .)
{txt} 18{com}.                 replace `z' = subinstr(`z', "â", "", .)
{txt} 19{com}.                 replace `z' = subinstr(`z', "â", "", .)    
{txt} 20{com}.                 replace `z' = subinstr(`z', "°", "", .)        
{txt} 21{com}.                 replace `z' = subinstr(`z',"Á","A",.)
{txt} 22{com}.                 replace `z' = subinstr(`z',"É","E",.)
{txt} 23{com}.                 replace `z' = subinstr(`z',"Í","I",.)
{txt} 24{com}.                 replace `z' = subinstr(`z',"Ó","O",.)
{txt} 25{com}.                 replace `z' = subinstr(`z',"Ú","U",.)
{txt} 26{com}.                 replace `z' = subinstr(`z',"Ü","U",.)
{txt} 27{com}.                 replace `z' = subinstr(`z',"Ñ","N",.)
{txt} 28{com}.                 replace `z' = subinstr(`z',"á","a",.)
{txt} 29{com}.                 replace `z' = subinstr(`z',"é","e",.)
{txt} 30{com}.                 replace `z' = subinstr(`z',"í","i",.)
{txt} 31{com}.                 replace `z' = subinstr(`z',"ó","o",.)
{txt} 32{com}.                 replace `z' = subinstr(`z',"ú","u",.)
{txt} 33{com}.                 replace `z' = subinstr(`z',"ñ","n",.)
{txt} 34{com}.                 replace `z' = subinstr(`z',"ü","u",.)
{txt} 35{com}. 
.                 global other ". , - _ | ( ) '"
{txt} 36{com}.                 foreach g of global other {c -(}
{txt} 37{com}.                         replace `z'=subinstr(`z',"`g'","",.)
{txt} 38{com}.                 {c )-}
{txt} 39{com}. 
.                 replace `z'=trim(`z')
{txt} 40{com}.                 replace `z'=ltrim(`z')
{txt} 41{com}.                 replace `z'=rtrim(`z')
{txt} 42{com}.                 replace `z'=itrim(`z')
{txt} 43{com}.                 replace `z'=lower(`z')
{txt} 44{com}.         {c )-}
{txt} 45{com}. end
{txt}
{com}. {txt}
{com}. 
. *-----------------------------------------------*
. * 1. 2012 Census data at the municipality level *
. *-----------------------------------------------*
. * Sheet POBLACION
. import excel "data/inputs/1_Bolivia_censo_poblacion_2012.xls", ///
>            clear sheet("POBLACIÓN")
{res}{txt}
{com}. 
. keep A O E L U-Z
{txt}
{com}. rename A mpio
{res}{txt}
{com}. rename E poblacion
{res}{txt}
{com}. rename O alfabetismo
{res}{txt}
{com}. rename L rural
{res}{txt}
{com}. rename V ed_prim
{res}{txt}
{com}. rename W ed_sec
{res}{txt}
{com}. 
. drop U X Y Z
{txt}
{com}. 
. gen depto=upper(mpio)
{txt}(14 missing values generated)

{com}. replace depto="" if mpio!=depto
{txt}(452 real changes made)

{com}. replace depto=depto[_n-1] if depto=="" & depto[_n-1]!=""
{txt}(466 real changes made)

{com}. drop if mpio==depto
{txt}(12 observations deleted)

{com}. gen prov = mpio if poblacion == ""
{txt}(353 missing values generated)

{com}. replace prov = prov[_n-1] if prov == "" & depto == depto[_n-1]
{txt}(351 real changes made)

{com}. drop if poblacion == ""
{txt}(126 observations deleted)

{com}. 
. drop in 1/1
{txt}(1 observation deleted)

{com}. compress
  {txt}variable {bf}mpio{sf} was {bf}{res}str80{sf}{txt} now {bf}{res}str26{sf}
  {txt}variable {bf}poblacion{sf} was {bf}{res}str27{sf}{txt} now {bf}{res}str7{sf}
  {txt}variable {bf}alfabetismo{sf} was {bf}{res}str55{sf}{txt} now {bf}{res}str17{sf}
  {txt}variable {bf}depto{sf} was {bf}{res}str80{sf}{txt} now {bf}{res}str10{sf}
  {txt}variable {bf}prov{sf} was {bf}{res}str42{sf}{txt} now {bf}{res}str23{sf}
{txt}  (68,139 bytes saved)

{com}. tempfile education
{txt}
{com}. save `education'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_000008.tmp saved

{com}. 
. * Sheet POBREZA
. import excel using "data/inputs/1_Bolivia_censo_poblacion_2012.xls", ///
>         clear sheet("POBREZA")
{res}{txt}
{com}. 
. keep A C
{txt}
{com}. rename A mpio
{res}{txt}
{com}. rename C pobreza
{res}{txt}
{com}. 
. gen depto=upper(mpio)
{txt}(15 missing values generated)

{com}. replace depto="" if mpio!=depto
{txt}(454 real changes made)

{com}. replace depto=depto[_n-1] if depto=="" & depto[_n-1]!=""
{txt}(469 real changes made)

{com}. drop if mpio==depto
{txt}(12 observations deleted)

{com}. gen prov = mpio if pobreza == ""
{txt}(354 missing values generated)

{com}. replace prov = prov[_n-1] if prov == "" & depto == depto[_n-1]
{txt}(352 real changes made)

{com}. drop if pobreza == ""
{txt}(130 observations deleted)

{com}. 
. compress
  {txt}variable {bf}mpio{sf} was {bf}{res}str387{sf}{txt} now {bf}{res}str26{sf}
  {txt}variable {bf}pobreza{sf} was {bf}{res}str30{sf}{txt} now {bf}{res}str17{sf}
  {txt}variable {bf}depto{sf} was {bf}{res}str387{sf}{txt} now {bf}{res}str10{sf}
  {txt}variable {bf}prov{sf} was {bf}{res}str387{sf}{txt} now {bf}{res}str23{sf}
{txt}  (377,985 bytes saved)

{com}. tempfile poverty
{txt}
{com}. save `poverty'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_000009.tmp saved

{com}. 
. * Sheet CARACTERÍSTICAS ECONÓMICAS
. import excel using "data/inputs/1_Bolivia_censo_poblacion_2012.xls", ///
>         clear sheet("CARACTERÍSTICAS ECONÓMICAS")
{res}{txt}
{com}. 
. keep A L
{txt}
{com}. rename A mpio
{res}{txt}
{com}. rename L agricultural_labor
{res}{txt}
{com}. 
. gen depto=upper(mpio)
{txt}(2 missing values generated)

{com}. replace depto="" if mpio!=depto
{txt}(453 real changes made)

{com}. replace depto=depto[_n-1] if depto=="" & depto[_n-1]!=""
{txt}(455 real changes made)

{com}. drop if mpio==depto
{txt}(12 observations deleted)

{com}. gen prov = mpio if agricultural_labor == ""
{txt}(341 missing values generated)

{com}. replace prov = prov[_n-1] if prov == "" & depto == depto[_n-1]
{txt}(339 real changes made)

{com}. drop if agricultural_labor == ""
{txt}(115 observations deleted)

{com}. 
. drop in 1/1
{txt}(1 observation deleted)

{com}. compress
  {txt}variable {bf}mpio{sf} was {bf}{res}str108{sf}{txt} now {bf}{res}str26{sf}
  {txt}variable {bf}agricultural_labor{sf} was {bf}{res}str64{sf}{txt} now {bf}{res}str17{sf}
  {txt}variable {bf}depto{sf} was {bf}{res}str108{sf}{txt} now {bf}{res}str10{sf}
  {txt}variable {bf}prov{sf} was {bf}{res}str82{sf}{txt} now {bf}{res}str23{sf}
{txt}  (96,954 bytes saved)

{com}. tempfile ag_labor
{txt}
{com}. save `ag_labor'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000a.tmp saved

{com}. 
. * Merge
. use `education', clear
{txt}
{com}. merge 1:1 depto prov mpio using `poverty'
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}             339{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _m
{txt}
{com}. replace prov = "Burnet Oconnor" if regexm(prov, "Burnet")
{txt}(1 real change made)

{com}. merge 1:1 depto prov mpio using `ag_labor'
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}             339{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _m
{txt}
{com}. 
. *Organize
. destring poblacion-agricultural_labor, replace
{txt}poblacion: all characters numeric; {res}replaced {txt}as {res}long
{txt}rural: all characters numeric; {res}replaced {txt}as {res}double
{txt}alfabetismo: all characters numeric; {res}replaced {txt}as {res}double
{txt}ed_prim: all characters numeric; {res}replaced {txt}as {res}double
{txt}ed_sec: all characters numeric; {res}replaced {txt}as {res}double
{txt}depto: contains nonnumeric characters; no {res}replace
{txt}prov: contains nonnumeric characters; no {res}replace
{txt}pobreza: all characters numeric; {res}replaced {txt}as {res}double
{txt}agricultural_labor: all characters numeric; {res}replaced {txt}as {res}double
{txt}
{com}. 
. superclean_basic depto
{txt}(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(40 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(339 real changes made)

{com}. superclean_basic prov
{txt}(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(6 real changes made)
(21 real changes made)
(16 real changes made)
(7 real changes made)
(0 real changes made)
(0 real changes made)
(14 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(339 real changes made)

{com}. superclean_basic mpio
{txt}(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(6 real changes made)
(8 real changes made)
(16 real changes made)
(8 real changes made)
(1 real change made)
(5 real changes made)
(0 real changes made)
(3 real changes made)
(0 real changes made)
(1 real change made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(1 real change made)
(339 real changes made)

{com}. 
. order depto prov mpio
{txt}
{com}. sort depto prov mpio
{txt}
{com}. compress
  {txt}variable {bf}mpio{sf} was {bf}{res}str26{sf}{txt} now {bf}{res}str25{sf}
{txt}  (339 bytes saved)

{com}. tempfile census2012_municipal
{txt}
{com}. save `census2012_municipal'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000b.tmp saved

{com}. 
. *------------------------------------------------------------------*
. * 2. Coordinates of Municipalities Centroides from ArcGIS                  *
. *------------------------------------------------------------------*
. insheet using "data/inputs/1_Bolivia_coordinates.txt", clear
{txt}(17 vars, 339 obs)

{com}. keep adm1_es adm2_es adm3_es coord*
{txt}
{com}. 
. superclean_basic adm*
{txt}(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(7 real changes made)
(9 real changes made)
(15 real changes made)
(9 real changes made)
(1 real change made)
(6 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(1 real change made)
(0 real changes made)
(0 real changes made)
(1 real change made)
(1 real change made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(1 real change made)
(337 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(6 real changes made)
(48 real changes made)
(29 real changes made)
(11 real changes made)
(6 real changes made)
(0 real changes made)
(14 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(1 real change made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(339 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(40 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(339 real changes made)

{com}. rename adm1 depto
{res}{txt}
{com}. rename adm2 prov
{res}{txt}
{com}. rename adm3 mpio
{res}{txt}
{com}. 
. do "codes/auxiliary_programs/2_data_names_coordinates.do"
{txt}
{com}. * This file is called within 1_Data_part2_covariates.do
. * The following lines of code were generated based on a fuzzy merge that
. * we then checked and revised by hand
. 
. replace mpio = "ayopaya villa de independencia" if mpio == "ayopaya" & prov == "ayopaya" & depto == "cochabamba"
{txt}(1 real change made)

{com}. replace mpio = "paria soracachi" if mpio == "paria" & prov == "cercado" & depto == "oruro"
{txt}(1 real change made)

{com}. replace mpio = "san benito villa jose quintin mendoza" if mpio == "san benito" & prov == "punata" & depto == "cochabamba"
{txt}variable {bf}mpio{sf} was {bf}{res}str33{sf}{txt} now {bf}{res}str37{sf}
{txt}(1 real change made)

{com}. replace mpio = "uriondo concepcion" if mpio == "uriondo" & prov == "aviles" & depto == "tarija"
{txt}(1 real change made)

{com}. replace mpio = "puna villa talavera" if mpio == "puna" & prov == "jose maria linares" & depto == "potosi"
{txt}(1 real change made)

{com}. 
. replace prov = "o connor" if prov == "oconnor" & depto == "tarija" 
{txt}(1 real change made)

{com}. replace prov = "sud lipez" if prov == "sur lipez" & depto == "potosi" 
{txt}(3 real changes made)

{com}. replace prov = "sud cinti" if prov == "sur cinti" & depto == "chuquisaca" 
{txt}(3 real changes made)

{com}. replace prov = "sud lipez" if prov == "sur lipez" & depto == "potosi" 
{txt}(0 real changes made)

{com}. replace prov = "sud cinti" if prov == "sur cinti" & depto == "chuquisaca" 
{txt}(0 real changes made)

{com}. replace prov = "sud cinti" if prov == "sur cinti" & depto == "chuquisaca" 
{txt}(0 real changes made)

{com}. replace prov = "sud lipez" if prov == "sur lipez" & depto == "potosi" 
{txt}(0 real changes made)

{com}. replace prov = "sud chichas" if prov == "sur chichas" & depto == "potosi" 
{txt}(2 real changes made)

{com}. replace prov = "sud chichas" if prov == "sur chichas" & depto == "potosi" 
{txt}(0 real changes made)

{com}. replace prov = "general bernardino bilbao" if prov == "general bilbao" & depto == "potosi" 
{txt}(2 real changes made)

{com}. replace prov = "general bernardino bilbao" if prov == "general bilbao" & depto == "potosi" 
{txt}(0 real changes made)

{com}. 
{txt}end of do-file

{com}. 
. tempfile coordinates
{txt}
{com}. save `coordinates'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000c.tmp saved

{com}. 
. *-------------------*
. * 3. Student's Data *
. *-------------------*
. insheet using "data/inputs/1_Bolivia_data_from_student.csv", clear
{txt}(28 vars, 5,135 obs)

{com}. 
. keep nomdep nomprov nombremunicipio asientoelectoral nombrerecinto density
{txt}
{com}. collapse (mean) density, by(nomdep nomprov nombremunicipio asientoelectoral nombrerecinto)
{txt}
{com}. 
. superclean_basic nomdep nomprov nombremunicipio asientoelectoral nombrerecinto
{txt}(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(679 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(5,114 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(66 real changes made)
(946 real changes made)
(746 real changes made)
(223 real changes made)
(39 real changes made)
(0 real changes made)
(515 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(32 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(5,114 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(49 real changes made)
(105 real changes made)
(279 real changes made)
(126 real changes made)
(15 real changes made)
(219 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(12 real changes made)
(0 real changes made)
(0 real changes made)
(97 real changes made)
(97 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(12 real changes made)
(5,083 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(14 real changes made)
(31 real changes made)
(90 real changes made)
(153 real changes made)
(80 real changes made)
(20 real changes made)
(301 real changes made)
(0 real changes made)
(56 real changes made)
(0 real changes made)
(32 real changes made)
(0 real changes made)
(0 real changes made)
(201 real changes made)
(201 real changes made)
(13 real changes made)
(1 real change made)
(0 real changes made)
(0 real changes made)
(13 real changes made)
(5,094 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(1 real change made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(5 real changes made)
(60 real changes made)
(54 real changes made)
(51 real changes made)
(53 real changes made)
(20 real changes made)
(145 real changes made)
(2 real changes made)
(3,448 real changes made)
(0 real changes made)
(47 real changes made)
(0 real changes made)
(0 real changes made)
(153 real changes made)
(151 real changes made)
(6 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(135 real changes made)
(5,109 real changes made)

{com}. 
. rename nomdep depto
{res}{txt}
{com}. rename nomprov prov
{res}{txt}
{com}. rename nombremunicipio mpio
{res}{txt}
{com}. rename asientoelectoral loc
{res}{txt}
{com}. rename nombrerecinto reci
{res}{txt}
{com}. 
. drop if reci == ""
{txt}(5 observations deleted)

{com}. 
. do "codes/auxiliary_programs/2_data_names_studentdata.do"
{txt}
{com}. * This file is called within 1_Data_part2_covariates.do
. * The following lines of code were generated based on a fuzzy merge that
. * we then checked and revised by hand
. 
. replace prov = "rafael bustillo" if prov == "bustillo"
{txt}(40 real changes made)

{com}. replace mpio = "santiago de andamarca" if mpio == "andamarca"
{txt}(3 real changes made)

{com}. 
. replace reci = subinstr(reci,"ue ","",.)
{txt}(1,454 real changes made)

{com}. replace reci = subinstr(reci,"u e ","",.)
{txt}(385 real changes made)

{com}. replace reci = trim(reci)
{txt}(0 real changes made)

{com}. replace reci = itrim(reci)
{txt}(0 real changes made)

{com}. 
. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "eduardo abaroa" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "eduardo abaroa" 
{txt}(0 real changes made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "litoral" 
{txt}(1 real change made)

{com}. replace mpio = "caiza d" if mpio == "" & prov == "jose maria linares" & reci == "normal rural caiza d" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "antofagasta" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "juana azurduy" 
{txt}(1 real change made)

{com}. replace mpio = "caiza d" if mpio == "" & prov == "jose maria linares" & reci == "esc tuctapari" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "tomas frias" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "alfonzo ibanes" 
{txt}(1 real change made)

{com}. replace mpio = "caiza d" if mpio == "" & prov == "jose maria linares" & reci == "col franz tamayo" 
{txt}(1 real change made)

{com}. replace mpio = "caiza d" if mpio == "" & prov == "jose maria linares" & reci == "san bartolome" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "buenas nuevas de vinto k" 
{txt}(1 real change made)

{com}. replace mpio = "caiza d" if mpio == "" & prov == "jose maria linares" & reci == "esc hornos" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "henry laredo" 
{txt}(1 real change made)

{com}. replace mpio = "caiza d" if mpio == "" & prov == "jose maria linares" & reci == "fragua" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "simon bolivar" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "ladislao cabrera" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "jose ballivian" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "esc tomas frias" 
{txt}(1 real change made)

{com}. replace mpio = "caiza d" if mpio == "" & prov == "jose maria linares" & reci == "21 de septiembre de la lava" 
{txt}(1 real change made)

{com}. replace mpio = "caiza d" if mpio == "" & prov == "jose maria linares" & reci == "esc de kaltapi" 
{txt}(1 real change made)

{com}. replace mpio = "caiza d" if mpio == "" & prov == "jose maria linares" & reci == "mcal antonio jose de sucre de tres cruces" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "eduardo abaroa de villa mar" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "esc santiago" 
{txt}(1 real change made)

{com}. replace mpio = "caiza d" if mpio == "" & prov == "jose maria linares" & reci == "esc palca cancha" 
{txt}(1 real change made)

{com}. replace mpio = "caiza d" if mpio == "" & prov == "jose maria linares" & reci == "pancochi" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "esc antofagasta" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "franz tamayo de pillina vilama" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "luis espinal" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "nuevo amanecer" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "ricardo rodriguez" 
{txt}(1 real change made)

{com}. replace mpio = "colcha k" if mpio == "" & prov == "nor lipez" & reci == "2 de agosto" 
{txt}(1 real change made)

{com}. replace mpio = "andamarca" if mpio == "santiago de andamarca"
{txt}(3 real changes made)

{com}. 
. replace loc = "rodeo a" if loc == "" & mpio == "vacas" & reci == "escuela seccional rodeo a" 
{txt}(1 real change made)

{com}. replace loc = "chaupisuyo a" if loc == "" & mpio == "ayopaya villa de independencia" & reci == "unidad educativa chapisuyo a" 
{txt}(1 real change made)

{com}. replace loc = "chaupisuyo b" if loc == "" & mpio == "morochata" & reci == "escuela 26 de mayo chaupisuyo b" 
{txt}(1 real change made)

{com}. replace loc = "molle pampa a" if loc == "" & mpio == "aiquile" & reci == "molle pampa" 
{txt}(1 real change made)

{com}. replace loc = "senda f 27 de mayo" if loc == "27 de mayo" & mpio == "chimore" & reci == "bolivia" 
{txt}(1 real change made)

{com}. replace loc = "senda 3" if loc == "" & mpio == "chimore" & reci == "senda iii" 
{txt}(1 real change made)

{com}. replace loc = "palca c" if loc == "" & mpio == "pojo" & reci == "unidad educativa palca c" 
{txt}(1 real change made)

{com}. replace loc = "rodeo c" if loc == "" & mpio == "pojo" & reci == "unidad educativa rodeo c" 
{txt}(1 real change made)

{com}. replace loc = "tiraque c" if loc == "" & mpio == "totora" & reci == "unidad educativa tiraqc" 
{txt}(1 real change made)

{com}. replace loc = "santa rosa n" if loc == "" & mpio == "shinahota" & reci == "marcelo quiroga santa cruz" 
{txt}(1 real change made)

{com}. replace loc = "palca t" if loc == "" & mpio == "tiraque" & reci == "unidad educativa palca t" 
{txt}(1 real change made)

{com}. replace loc = "bella vista a" if loc == "" & mpio == "teoponte" & reci == "nucleo red uno" 
{txt}(1 real change made)

{com}. replace loc = "central vila vila a" if loc == "" & mpio == "caracollo" & reci == "casa comunal" 
{txt}(1 real change made)

{com}. replace loc = "condo k" if loc == "" & mpio == "santiago de huari" & reci == "esc condo k" 
{txt}(1 real change made)

{com}. replace loc = "condo ccsan pedro de condo" if loc == "csan pedro de condo" & mpio == "santiago de huari" & reci == "san pedro de condo" 
{txt}(1 real change made)

{com}. replace loc = "totora k" if loc == "" & mpio == "tomave" & reci == "1ro de mayo" 
{txt}(1 real change made)

{com}. replace loc = "tomoyo b" if loc == "" & mpio == "pocoata" & reci == "tomoyo" 
{txt}(1 real change made)

{com}. replace loc = "caiza d" if loc == "" & mpio == "caiza d" & reci == "normal rural caiza d" 
{txt}(1 real change made)

{com}. replace loc = "culpina k" if loc == "" & mpio == "colcha k" & reci == "eduardo abaroa" 
{txt}(1 real change made)

{com}. replace loc = "colcha k" if loc == "" & mpio == "colcha k" & reci == "eduardo abaroa" 
{txt}(0 real changes made)

{com}. replace loc = "calcha k" if loc == "" & mpio == "colcha k" & reci == "litoral" 
{txt}(1 real change made)

{com}. replace loc = "totora d" if loc == "" & mpio == "yocalla" & reci == "esc jose antonio zampa" 
{txt}(1 real change made)

{com}. replace loc = "san juan" if loc == "san juan de yapacani" & mpio == "san juan" & reci == "esc popular don bosco" 
{txt}(1 real change made)

{com}. replace loc = "caizaj" if loc == "" & mpio == "yacuiba" & reci == "prof bautista jurado" 
{txt}(1 real change made)

{com}. 
. replace reci = "iptk" if reci == "iptkn aguirre 560 / cerpi" & loc == "sucre" & mpio == "sucre" & prov == "oropeza" 
{txt}(1 real change made)

{com}. replace reci = "esc sub" if reci == "esc subcentral pueblo nuevo" & loc == "pueblo nuevo" & mpio == "san ignacio" & prov == "moxos" 
{txt}(1 real change made)

{com}. replace reci = "sede sub" if reci == "sede sub central viscachas" & loc == "viscachas" & mpio == "cocapata" & prov == "ayopaya" 
{txt}(1 real change made)

{com}. replace reci = "sede social" if reci == "sede social esc fiscal calizaya" & loc == "calizaya" & mpio == "la asunta" & prov == "sud yungas" 
{txt}(1 real change made)

{com}. replace reci = "franz tamayo" if reci == "franz tamayo villa esperanza" & loc == "villa esperanza" & mpio == "corque" & prov == "carangas" 
{txt}(1 real change made)

{com}. replace reci = "esc more" if reci == "esc moremonte azul" & loc == "moremonte azul" & mpio == "san joaquin" & prov == "mamore" 
{txt}(1 real change made)

{com}. replace reci = "u esc el kasso" if reci == "u esc el kasso el progreso" & loc == "oruro" & mpio == "oruro" & prov == "cercado" 
{txt}(1 real change made)

{com}. replace reci = "unidad educativa santa cruz" if reci == "unidad educativa santa cruz eduardo ocampo moscoso" & loc == "cochabamba" & mpio == "cochabamba" & prov == "cercado" 
{txt}(1 real change made)

{com}. replace reci = "esc la isiga" if reci == "esc la isigapersevera" & loc == "la isiga/perseverancia" & mpio == "san andres" & prov == "marban" 
{txt}(1 real change made)

{com}. replace reci = "esc la pena" if reci == "esc la pena brecha3" & loc == "brecha 3" & mpio == "la guardia" & prov == "andres ibanez" 
{txt}(1 real change made)

{com}. replace reci = "escuela 26 de mayo" if reci == "escuela 26 de mayo chaupisuyo b" & loc == "chaupisuyo b" & mpio == "morochata" & prov == "ayopaya" 
{txt}(1 real change made)

{com}. replace reci = "valle hermoso" if reci == "valle hermoso vinto ii" & loc == "oruro" & mpio == "oruro" & prov == "cercado" 
{txt}(1 real change made)

{com}. replace reci = "nueva jerusalen" if reci == "nueva jerusalenpentaguazu" & loc == "satelite norte" & mpio == "warnes" & prov == "warnes" 
{txt}(1 real change made)

{com}. replace reci = "col rvdo victor aruazo" if reci == "col rvdo victor aruazoplaza principal" & loc == "luribay" & mpio == "luribay" & prov == "loayza" 
{txt}(1 real change made)

{com}. replace reci = "unidad educativa siglo xx" if reci == "unidad educativa siglo xx gabriela mistral" & loc == "cochabamba" & mpio == "cochabamba" & prov == "cercado" 
{txt}(1 real change made)

{com}. replace reci = "col la resureccion" if reci == "col la resureccion esc convif" & loc == "santa cruz de la sierra" & mpio == "santa cruz de la sierra" & prov == "andres ibanez" 
{txt}(1 real change made)

{com}. replace reci = "escuela oscar alfaro" if reci == "escuela oscar alfaro villa vinto" & loc == "villa vinto" & mpio == "cocapata" & prov == "ayopaya" 
{txt}(1 real change made)

{com}. replace reci = "esc san pablo" if reci == "esc san pabloisiboro" & loc == "san pablo del isiboro" & mpio == "loreto" & prov == "marban" 
{txt}(1 real change made)

{com}. replace reci = "rene barrientos o" if reci == "rene barrientos o la villa" & loc == "la villa" & mpio == "punata" & prov == "punata" 
{txt}(1 real change made)

{com}. replace reci = "escuela juana azurduy" if reci == "escuela juana azurduy pongo kasa" & loc == "pongo kasa" & mpio == "arque" & prov == "arque" 
{txt}(1 real change made)

{com}. replace reci = "coleg siglo xx" if reci == "coleg siglo xxamerica" & loc == "llallagua" & mpio == "llallagua" & prov == "rafael bustillo" 
{txt}(1 real change made)

{com}. replace reci = "escuela 6 de junio" if reci == "escuela 6 de junio tacopoca" & loc == "lava lava" & mpio == "sacaba" & prov == "chapare" 
{txt}(1 real change made)

{com}. replace reci = "esc esteban andia escobar" if reci == "esc esteban andia escobar paccha pata" & loc == "paccha pata" & mpio == "anzaldo" & prov == "esteban arze" 
{txt}(1 real change made)

{com}. replace reci = "colegio domingo savio" if reci == "colegio domingo savio don bosco" & loc == "santa cruz de la sierra" & mpio == "santa cruz de la sierra" & prov == "andres ibanez" 
{txt}(1 real change made)

{com}. replace reci = "unidad educativa paraiso" if reci == "unidad educativa paraisotodo santos" & loc == "paraisotodo santos" & mpio == "villa tunari" & prov == "chapare" 
{txt}(1 real change made)

{com}. replace reci = "escuela eliseo torrico" if reci == "escuela eliseo torrico sacabamba" & loc == "sacabamba" & mpio == "sacabamba" & prov == "esteban arze" 
{txt}(1 real change made)

{com}. replace reci = "u esc luis llosa" if reci == "u esc luis llosa espana" & loc == "oruro" & mpio == "oruro" & prov == "cercado" 
{txt}(1 real change made)

{com}. replace reci = "escuela mariano baptista" if reci == "escuela mariano baptista morochata" & loc == "morochata" & mpio == "morochata" & prov == "ayopaya" 
{txt}(1 real change made)

{com}. replace reci = "unidad educativa america del sur" if reci == "unidad educativa america del sur mejillones a" & loc == "cochabamba" & mpio == "cochabamba" & prov == "cercado" 
{txt}(1 real change made)

{com}. replace reci = "unidad educativa flora salinas hinojosa" if reci == "unidad educativa flora salinas hinojosa amalia echalar" & loc == "quillacollo" & mpio == "quillacollo" & prov == "quillacollo" 
{txt}(1 real change made)

{com}. replace reci = "unidad escolar tupac katari" if reci == "unidad escolar tupac katari tarujayna" & loc == "tarujayna" & mpio == "arque" & prov == "arque" 
{txt}(1 real change made)

{com}. replace reci = "san jose de calazans" if reci == "san jose de calazanslitoral" & loc == "anzaldo" & mpio == "anzaldo" & prov == "esteban arze" 
{txt}(1 real change made)

{com}. replace reci = "escuela pedro domingo murillo" if reci == "escuela pedro domingo murillo calientes" & loc == "calientes" & mpio == "cocapata" & prov == "ayopaya" 
{txt}(1 real change made)

{com}. replace reci = "colegio 24 de septiembre" if reci == "colegio 24 de septiembre maragua" & loc == "maragua" & mpio == "sucre" & prov == "oropeza" 
{txt}(1 real change made)

{com}. replace reci = "unidad educativa 6 de junio" if reci == "unidad educativa 6 de junio mamanaca" & loc == "mamanaca" & mpio == "arbieto" & prov == "esteban arze" 
{txt}(1 real change made)

{com}. replace reci = "unidad educativa cauchi" if reci == "unidad educativa cauchi titiri" & loc == "cauchititiri" & mpio == "patacamaya" & prov == "aroma" 
{txt}(1 real change made)

{com}. replace reci = "unidad educativa antonio arnez" if reci == "unidad educativa antonio arnez aranjuez" & loc == "aranjuez" & mpio == "arbieto" & prov == "esteban arze" 
{txt}(1 real change made)

{com}. replace reci = "escuela julio espinoza canelas" if reci == "escuela julio espinoza canelaspunacachi" & loc == "punacachi" & mpio == "morochata" & prov == "ayopaya" 
{txt}(1 real change made)

{com}. replace reci = "colegio rene barrientos ortuno" if reci == "colegio rene barrientos ortuno piusilla" & loc == "piusillas" & mpio == "morochata" & prov == "ayopaya" 
{txt}(1 real change made)

{com}. replace reci = "centro integrado el salvador s" if reci == "centro integrado el salvador svera cruz" & loc == "cochabamba" & mpio == "cochabamba" & prov == "cercado" 
{txt}(1 real change made)

{com}. replace reci = "escuela hilarion grageda" if reci == "escuela hilarion grageda yayani" & loc == "yayani" & mpio == "morochata" & prov == "ayopaya" 
{txt}(1 real change made)

{com}. replace reci = "centro educativo german busch" if reci == "centro educativo german busch arbieto" & loc == "arbieto" & mpio == "arbieto" & prov == "esteban arze" 
{txt}(1 real change made)

{com}. replace reci = "unidad educativa bolivia" if reci == "unidad educativa boliviaviloco" & loc == "viloco" & mpio == "cairoma" & prov == "loayza" 
{txt}(1 real change made)

{com}. replace reci = "esc gualberto villarroel" if reci == "esc gualberto villarroel iruni" & loc == "iruni" & mpio == "turco" & prov == "sajama" 
{txt}(1 real change made)

{com}. replace reci = "unidad educativa kara huasi" if reci == "unidad educativa kara huasi pojo" & loc == "kara huasi" & mpio == "pojo" & prov == "carrasco" 
{txt}(1 real change made)

{com}. replace reci = "inst de aprendizaje industrial" if reci == "inst de aprendizaje industrial iai" & loc == "oruro" & mpio == "oruro" & prov == "cercado" 
{txt}(1 real change made)

{com}. replace reci = "unidad educativa privada la paz 1" if reci == "unidad educativa privada la paz" & loc == "nuestra senora de la paz" & mpio == "nuestra senora de la paz" & prov == "murillo" 
{txt}(1 real change made)

{com}. 
. 
{txt}end of do-file

{com}. 
. compress 
  {txt}variable {bf}prov{sf} was {bf}{res}str26{sf}{txt} now {bf}{res}str25{sf}
  {txt}variable {bf}mpio{sf} was {bf}{res}str41{sf}{txt} now {bf}{res}str37{sf}
  {txt}variable {bf}reci{sf} was {bf}{res}str69{sf}{txt} now {bf}{res}str66{sf}
{txt}  (40,872 bytes saved)

{com}. tempfile students_data
{txt}
{com}. save `students_data'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000d.tmp saved

{com}. 
. *--------------------*
. * 4. 2016 data           *
. *--------------------*
. do "codes/additional_code/merge_2016_2019.do"
{txt}
{com}. clear
{txt}
{com}. 
. cap program drop superclean_basic
{txt}
{com}. include "codes/auxiliary_programs/superclean_basic.ado"
{txt}
{com}. cap program drop superclean_basic
{txt}
{com}. program define superclean_basic
{txt}  1{com}.         syntax varlist(min=1)
{txt}  2{com}. 
.         foreach z of varlist `varlist' {c -(}
{txt}  3{com}.                 replace `z' = subinstr(`z', "Ã", "A", .)
{txt}  4{com}.                 replace `z'= subinstr(`z',"Ã","A",.)
{txt}  5{com}.                 replace `z'= subinstr(`z',"Ã","A",.)
{txt}  6{com}.                 replace `z'= subinstr(`z',"Ã","A",.)
{txt}  7{com}.                 replace `z'= subinstr(`z',"Ã","A",.)
{txt}  8{com}.                 replace `z' = subinstr(`z', "Ã", "E", .)
{txt}  9{com}.                 replace `z' = subinstr(`z', "Ã", "I", .)
{txt} 10{com}.                 replace `z' = subinstr(`z', "Ã", "U", .)
{txt} 11{com}.                 replace `z' = subinstr(`z', "Ã", "O", .)
{txt} 12{com}.                 replace `z' = subinstr(`z', "Ã", "N", .)
{txt} 13{com}.                 replace `z' = subinstr(`z', "NÂ°", "nº", .)
{txt} 14{com}.                 replace `z' = subinstr(`z', "NÂº", "nº", .)  
{txt} 15{com}.                 replace `z' = subinstr(`z', `"""', "", .)
{txt} 16{com}.                 replace `z' = subinstr(`z', "Â", "", .)
{txt} 17{com}.                 replace `z' = subinstr(`z', "â", "", .)
{txt} 18{com}.                 replace `z' = subinstr(`z', "â", "", .)
{txt} 19{com}.                 replace `z' = subinstr(`z', "â", "", .)    
{txt} 20{com}.                 replace `z' = subinstr(`z', "°", "", .)        
{txt} 21{com}.                 replace `z' = subinstr(`z',"Á","A",.)
{txt} 22{com}.                 replace `z' = subinstr(`z',"É","E",.)
{txt} 23{com}.                 replace `z' = subinstr(`z',"Í","I",.)
{txt} 24{com}.                 replace `z' = subinstr(`z',"Ó","O",.)
{txt} 25{com}.                 replace `z' = subinstr(`z',"Ú","U",.)
{txt} 26{com}.                 replace `z' = subinstr(`z',"Ü","U",.)
{txt} 27{com}.                 replace `z' = subinstr(`z',"Ñ","N",.)
{txt} 28{com}.                 replace `z' = subinstr(`z',"á","a",.)
{txt} 29{com}.                 replace `z' = subinstr(`z',"é","e",.)
{txt} 30{com}.                 replace `z' = subinstr(`z',"í","i",.)
{txt} 31{com}.                 replace `z' = subinstr(`z',"ó","o",.)
{txt} 32{com}.                 replace `z' = subinstr(`z',"ú","u",.)
{txt} 33{com}.                 replace `z' = subinstr(`z',"ñ","n",.)
{txt} 34{com}.                 replace `z' = subinstr(`z',"ü","u",.)
{txt} 35{com}. 
.                 global other ". , - _ | ( ) '"
{txt} 36{com}.                 foreach g of global other {c -(}
{txt} 37{com}.                         replace `z'=subinstr(`z',"`g'","",.)
{txt} 38{com}.                 {c )-}
{txt} 39{com}. 
.                 replace `z'=trim(`z')
{txt} 40{com}.                 replace `z'=ltrim(`z')
{txt} 41{com}.                 replace `z'=rtrim(`z')
{txt} 42{com}.                 replace `z'=itrim(`z')
{txt} 43{com}.                 replace `z'=lower(`z')
{txt} 44{com}.         {c )-}
{txt} 45{com}. end
{txt}
{com}. {txt}
{com}. 
. *--------------------------------------------------*
. * Loading the 2016 ELECTORAL data for BOLIVIA only *
. *--------------------------------------------------*
. * Loading Bolivia
. import delimited "data/inputs/1_Bolivia_votos_totales_ref_2016.csv", ///
>         clear delim("|")
{res}{text}(19 vars, 29,224 obs)

{com}. 
. * Make recinto code from mesa code (?)
. drop codigorecinto      
{txt}
{com}. tostring codigomesa, replace
{txt}codigomesa was {res:long} now {res:str5}

{com}. gen codigorecinto = substr(codigomesa, 1, 3)
{txt}
{com}. destring codigorecinto, replace
{txt}codigorecinto: all characters numeric; {res}replaced {txt}as {res}int
{txt}
{com}. 
. * Keep  
. keep codigodepartamento codigoprovincia ///
>         codigomunicipio nombrerecinto codigorecinto no-validos
{txt}
{com}. 
. cap rename sã si
{txt}
{com}. 
. * Standardizing the precinct name
. superclean_basic nombrerecinto
{txt}(105 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(129 real changes made)
(215 real changes made)
(9 real changes made)
(149 real changes made)
(979 real changes made)
(6 real changes made)
(0 real changes made)
(1,014 real changes made)
(5 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(15,706 real changes made)
(21 real changes made)
(908 real changes made)
(0 real changes made)
(0 real changes made)
(1,061 real changes made)
(1,011 real changes made)
(11 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(807 real changes made)
(29,224 real changes made)

{com}. 
. compress
  {txt}variable {bf}nombrerecinto{sf} was {bf}{res}str69{sf}{txt} now {bf}{res}str67{sf}
{txt}  (58,448 bytes saved)

{com}. 
. * Collapsing at the precinct level
. collapse (sum) no-validos, ///
>              by(codigodepartamento codigoprovincia codigomunicipio nombrerecinto codigorecinto)
{txt}
{com}. 
. * Identifying potential duplicates (this is the merge with 2016 padrón)
. duplicates tag codigodepartamento codigoprovincia codigomunicipio inscritos, gen(tag)

{p 0 4}{txt}Duplicates in terms of {res} codigodepartamento codigoprovincia codigomunicipio inscritos{p_end}
{txt}
{com}. 
. * Saving the unique observations
. preserve
{txt}
{com}.         keep if tag==0
{txt}(132 observations deleted)

{com}.         drop tag
{txt}
{com}.         compress
  {txt}variable {bf}no{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}si{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}blancos{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}emitidos{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}inscritos{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}nulos{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}validos{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
{txt}  (203,700 bytes saved)

{com}.         sort codigodepartamento codigoprovincia codigomunicipio nombrerecinto
{txt}
{com}.         tempfile bolivia_2016_recinto
{txt}
{com}.         save `bolivia_2016_recinto'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000f.tmp saved

{com}. restore
{txt}
{com}. 
. * Saving the duplicates
. keep if tag!=0
{txt}(4,850 observations deleted)

{com}. drop tag
{txt}
{com}. compress
  {txt}variable {bf}no{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}si{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}blancos{sf} was {bf}{res}double{sf}{txt} now {bf}{res}byte{sf}
  {txt}variable {bf}emitidos{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}inscritos{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}nulos{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}validos{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}nombrerecinto{sf} was {bf}{res}str67{sf}{txt} now {bf}{res}str43{sf}
{txt}  (8,844 bytes saved)

{com}. sort codigodepartamento codigoprovincia codigomunicipio nombrerecinto
{txt}
{com}. tempfile bolivia_2016_recinto_dups
{txt}
{com}. save `bolivia_2016_recinto_dups'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000g.tmp saved

{com}. 
. *---------------------*
. * Loading Padron 2016 *
. *---------------------*
. * Bolivia
. import excel using "data/inputs/1_Bolivia_padron_ref_const_2016.xlsx", ///
>         clear first sheet("Ciu_hab_por mesa NACIONAL") cellrange("A5:P29229")
{res}{txt}
{com}. 
. * Using lowercase names for variables
. foreach x of varlist _all {c -(}
{txt}  2{com}.         local t=lower("`x'")
{txt}  3{com}.         rename `x' `t'
{txt}  4{com}. {c )-}
{res}{txt}  (all {it:newnames}=={it:oldnames})
{res}{txt}
{com}. 
. gen ciud_orig=ciudadanos 
{txt}
{com}.  
. gen codrecinto=substr(nummesa,1,16) 
{txt}
{com}. keep dep prov sec ciudadanos nombrerecinto ciud_orig nummesa codrecinto
{txt}
{com}. 
. * Standardizing the precinct name
. superclean_basic nombrerecinto
{txt}(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(1,015 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(6 real changes made)
(25 real changes made)
(43 real changes made)
(98 real changes made)
(51 real changes made)
(3 real changes made)
(1 real change made)
(775 real changes made)
(80 real changes made)
(86 real changes made)
(117 real changes made)
(98 real changes made)
(6 real changes made)
(204 real changes made)
(0 real changes made)
(15,706 real changes made)
(21 real changes made)
(908 real changes made)
(0 real changes made)
(0 real changes made)
(1,061 real changes made)
(1,011 real changes made)
(11 real changes made)
(26,897 real changes made)
(0 real changes made)
(0 real changes made)
(807 real changes made)
(29,224 real changes made)

{com}. 
. compress
  {txt}variable {bf}ciud_orig{sf} was {bf}{res}float{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}nombrerecinto{sf} was {bf}{res}str69{sf}{txt} now {bf}{res}str67{sf}
{txt}  (116,896 bytes saved)

{com}. 
. * Modifying the province code, and generating a municipality code
. replace prov=prov+100*dep
{txt}variable {bf}prov{sf} was {bf}{res}byte{sf}{txt} now {bf}{res}int{sf}
{txt}(29,224 real changes made)

{com}. *---*
. tostring sec, gen(sec2)
{txt}sec2 generated as {res:str1}

{com}. replace sec2="0"+sec2
{txt}variable {bf}sec2{sf} was {bf}{res}str1{sf}{txt} now {bf}{res}str2{sf}
{txt}(29,224 real changes made)

{com}. tostring prov, gen(prov2)
{txt}prov2 generated as {res:str3}

{com}. gen codmun=prov2+sec2
{txt}
{com}. order codmun, after(prov)
{txt}
{com}. destring codmun, replace
{txt}codmun: all characters numeric; {res}replaced {txt}as {res}long
{txt}
{com}. drop sec2 prov2 sec
{txt}
{com}. 
. * Collapsing at the precinct level
. collapse (sum) ciudadanos ciud_orig (first) nombrerecinto, by(dep prov codmun codrecinto)
{txt}
{com}. 
. * In these ten recintos, the number of inscritos is off by one
. foreach cod in "1003203096409046" "1003203089706006" "1003202060102864" ///
>                            "1003202065402314" "1003207223406010" "1003207223410020" ///
>                        "1003207225411024" "1003208278400006" {c -(}
{txt}  2{com}.         replace ciudadanos = ciudadanos - 1     if codrecinto == "`cod'"                        
{txt}  3{com}. {c )-} 
{txt}(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)
(1 real change made)

{com}. 
. * Identifying potential duplicates
. duplicates tag dep prov codmun ciudadanos, gen(tag)

{p 0 4}{txt}Duplicates in terms of {res} dep prov codmun ciudadanos{p_end}
{txt}
{com}. 
. * Saving the unique observations
. preserve
{txt}
{com}.         keep if tag==0
{txt}(118 observations deleted)

{com}.         drop tag
{txt}
{com}.         tempfile padron_bolivia
{txt}
{com}.         save `padron_bolivia'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000i.tmp saved

{com}. restore
{txt}
{com}. 
. * Saving the duplicates
. keep if tag!=0
{txt}(4,667 observations deleted)

{com}. drop tag
{txt}
{com}. compress
  {txt}variable {bf}ciudadanos{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}ciud_orig{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}nombrerecinto{sf} was {bf}{res}str67{sf}{txt} now {bf}{res}str43{sf}
{txt}  (4,248 bytes saved)

{com}. sort dep prov codmun nombrerecinto
{txt}
{com}. tempfile padron_bolivia_dups
{txt}
{com}. save `padron_bolivia_dups'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000j.tmp saved

{com}. 
. *-----------------------------------------------*
. * Merging the non-problematic datasets (tag==0) *
. *-----------------------------------------------*
. use `padron_bolivia', clear
{txt}
{com}. 
. rename dep codigodepartamento
{res}{txt}
{com}. rename prov codigoprovincia
{res}{txt}
{com}. rename codmun codigomunicipio
{res}{txt}
{com}. rename ciudadanos inscritos
{res}{txt}
{com}. merge 1:1 codigodepartamento codigoprovincia codigomunicipio inscritos using `bolivia_2016_recinto'
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}             839
{txt}{col 9}from master{col 30}{res}             328{txt}  (_merge==1)
{col 9}from using{col 30}{res}             511{txt}  (_merge==2)

{col 5}matched{col 30}{res}           4,339{txt}  (_merge==3)
{col 5}{hline 41}

{com}. 
. * Saving the observations that merge
. tempfile merged1
{txt}
{com}. savesome if _m == 3 using `merged1' 
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000k.tmp saved

{com}. 
. * Artificial split recintos in the electoral data
. preserve
{txt}
{com}.         keep if _m == 2
{txt}(4,667 observations deleted)

{com}.         collapse (sum) inscritos no-validos, ///
>                           by(codigodepartamento codigoprovincia codigomunicipio nombrerecinto)
{txt}
{com}.         duplicates tag codigodepartamento codigoprovincia codigomunicipio inscritos, gen(tag)

{p 0 4}{txt}Duplicates in terms of {res} codigodepartamento codigoprovincia codigomunicipio inscritos{p_end}
{txt}
{com}.         keep if tag == 0
{txt}(4 observations deleted)

{com}.         drop tag
{txt}
{com}.         tempfile artificial_splits_2016electoral
{txt}
{com}.         save `artificial_splits_2016electoral'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000m.tmp saved

{com}. restore
{txt}
{com}. 
. * Merge (collapsed) fake duplicates back to unmatched 2016 padrón observations
. keep if _m == 1
{txt}(4,850 observations deleted)

{com}. keep codigodepartamento codigoprovincia codigomunicipio inscritos nombrerecinto codrecinto
{txt}
{com}. merge 1:1 codigodepartamento codigoprovincia codigomunicipio inscritos using `artificial_splits_2016electoral'
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}             159
{txt}{col 9}from master{col 30}{res}             105{txt}  (_merge==1)
{col 9}from using{col 30}{res}              54{txt}  (_merge==2)

{col 5}matched{col 30}{res}             223{txt}  (_merge==3)
{col 5}{hline 41}

{com}. tempfile merged2
{txt}
{com}. rename _m merged
{res}{txt}
{com}. savesome if merged == 3 using `merged2' 
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000n.tmp saved

{com}. 
. *-------------------------------------------*
. * Merging the problematic datasets (tag!=0) *
. *-------------------------------------------*
. use `padron_bolivia_dups', clear
{txt}
{com}. 
. * Merging with the problematic observations from the 2016 electoral dataset
. rename dep codigodepartamento
{res}{txt}
{com}. rename prov codigoprovincia
{res}{txt}
{com}. rename codmun codigomunicipio
{res}{txt}
{com}. rename ciudadanos inscritos
{res}{txt}
{com}. merge 1:1 codigodepartamento codigoprovincia codigomunicipio inscritos nombrerecinto using `bolivia_2016_recinto_dups'
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}              26
{txt}{col 9}from master{col 30}{res}               6{txt}  (_merge==1)
{col 9}from using{col 30}{res}              20{txt}  (_merge==2)

{col 5}matched{col 30}{res}             112{txt}  (_merge==3)
{col 5}{hline 41}

{com}. 
. tempfile merged3
{txt}
{com}. savesome if _m ==3 using `merged3'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000o.tmp saved

{com}. 
. *------------------------------------------------------*
. * Appending the successfully merged resulting datasets *
. *------------------------------------------------------*
. use `merged1', clear
{txt}
{com}. append using `merged2'
{txt}{p 0 7 2}
(note: variable
no was 
int, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
si was 
int, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
blancos was 
int, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
emitidos was 
int, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
nulos was 
int, now double to accommodate using data's values)
{p_end}
{p 0 7 2}
(note: variable
validos was 
int, now double to accommodate using data's values)
{p_end}
(label _merge already defined)

{com}. append using `merged3'
{txt}(label _merge already defined)

{com}. 
. rename nombrerecinto recinto2016
{res}{txt}
{com}. drop _m merged
{txt}
{com}. tempfile e2016_with_codrecinto
{txt}
{com}. save `e2016_with_codrecinto'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000p.tmp saved

{com}. 
. *-----------------------------------------*
. * Merging 2019 with 2016 Padron+Electoral *
. *-----------------------------------------*
. import excel using "data/inputs/1_Bolivia_acta.2021.12.03.16.13.58.xlsx", ///
>         clear first
{res}{txt}
{com}. 
. keep if Elección=="Presidente y Vicepresidente" & País=="Bolivia"
{txt}(35,092 observations deleted)

{com}. keep NúmeroMesa CódigoMesa Recinto
{txt}
{com}. 
. gen codrecinto=substr(CódigoMesa,1,16)
{txt}
{com}. 
. merge m:1 codrecinto using `e2016_with_codrecinto'
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}           2,552
{txt}{col 9}from master{col 30}{res}           2,389{txt}  (_merge==1)
{col 9}from using{col 30}{res}             163{txt}  (_merge==2)

{col 5}matched{col 30}{res}          30,659{txt}  (_merge==3)
{col 5}{hline 41}

{com}. 
. preserve
{txt}
{com}.         keep if _merge==3
{txt}(2,552 observations deleted)

{com}.         keep NúmeroMesa CódigoMesa recinto2016 no-validos
{txt}
{com}.         renvars no-validos, postfix(2016)
{txt}
{com}.         compress
  {txt}variable {bf}no2016{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}si2016{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}blancos2016{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}emitidos2016{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}nulos2016{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}validos2016{sf} was {bf}{res}double{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}recinto2016{sf} was {bf}{res}str67{sf}{txt} now {bf}{res}str66{sf}
{txt}  (1,134,383 bytes saved)

{com}.         tempfile 2019_2016_ours
{txt}
{com}.         save `2019_2016_ours'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000r.tmp saved

{com}. restore 
{txt}
{com}. 
. *----------------------------------------------*
. * Use Rosnick data to match unmerged obs.      *
. *----------------------------------------------*
. keep if _merge==1
{txt}(30,822 observations deleted)

{com}. drop _merge
{txt}
{com}. 
. keep NúmeroMesa CódigoMesa Recinto
{txt}
{com}. 
. gen idpais=substr(CódigoMesa,3,3)
{txt}
{com}. gen idDep=substr(CódigoMesa,6,2)
{txt}
{com}. gen idLoc=substr(CódigoMesa,8,4)
{txt}
{com}. gen idReci=substr(CódigoMesa,12,5)
{txt}
{com}. gen mesa=substr(CódigoMesa,17,2)
{txt}
{com}. destring idpais-mesa, replace
{txt}idpais: all characters numeric; {res}replaced {txt}as {res}byte
{txt}idDep: all characters numeric; {res}replaced {txt}as {res}byte
{txt}idLoc: all characters numeric; {res}replaced {txt}as {res}int
{txt}idReci: all characters numeric; {res}replaced {txt}as {res}int
{txt}mesa: all characters numeric; {res}replaced {txt}as {res}byte
{txt}
{com}. 
. * Note: this is the 2016:2019 merge shared by David Rosnick
. merge m:1 idpais idDep idLoc idReci using "data/inputs/1_Bolivia_2016-2019_alternate_merge.dta"
{res}{txt}{p 0 7 2}
(note: variable
idpais was 
byte, now int to accommodate using data's values)
{p_end}

{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}           4,676
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}           4,676{txt}  (_merge==2)

{col 5}matched{col 30}{res}           2,389{txt}  (_merge==3)
{col 5}{hline 41}

{com}. 
. drop if _merge==2
{txt}(4,676 observations deleted)

{com}. drop _merge
{txt}
{com}. 
. rename mSÍ mSI
{res}{txt}
{com}. foreach x in Recinto NO SI BLANCOS EMITIDOS INSCRITOS NULOS VALIDOS {c -(}
{txt}  2{com}.         local t=lower("`x'")
{txt}  3{com}.         rename m`x' `t'2016
{txt}  4{com}. {c )-}
{res}{txt}
{com}. 
. keep NúmeroMesa CódigoMesa recinto2016-validos2016
{txt}
{com}. 
. * Standardizing the precinct name
. superclean_basic recinto2016
{txt}(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(43 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(1 real change made)
(65 real changes made)
(104 real changes made)
(54 real changes made)
(98 real changes made)
(56 real changes made)
(50 real changes made)
(0 real changes made)
(1,684 real changes made)
(0 real changes made)
(406 real changes made)
(0 real changes made)
(0 real changes made)
(44 real changes made)
(44 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(434 real changes made)
(2,389 real changes made)

{com}. 
. gen dr=1
{txt}
{com}. 
. *-----------------------------------------*
. * Append both sets of matched obs.        *
. *-----------------------------------------*
. append using `2019_2016_ours'
{txt}
{com}. replace dr=0 if dr==.
{txt}(30,659 real changes made)

{com}. 
. assert _N == 33048
{txt}
{com}. 
. rename dr dr2016
{res}{txt}
{com}. 
. *---
. 
{txt}end of do-file

{com}. 
. rename NúmeroMesa NumMesa
{res}{txt}
{com}. 
. compress
  {txt}variable {bf}nulos2016{sf} was {bf}{res}long{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}dr2016{sf} was {bf}{res}float{sf}{txt} now {bf}{res}byte{sf}
  {txt}variable {bf}recinto2016{sf} was {bf}{res}str84{sf}{txt} now {bf}{res}str66{sf}
{txt}  (760,104 bytes saved)

{com}. tempfile merge_2019_2016
{txt}
{com}. save `merge_2019_2016'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000e.tmp saved

{com}. 
. *-------------------------------------------------------------------*
. * 4. Create data set of covariates with numeric ID from main data   *
. *-------------------------------------------------------------------*
. * Keep identifiers from 2019 electoral data     
. use "data/outputs/computo_ulttranstrepdate_missingsatmunmedian.dta", clear
{txt}
{com}. keep Pais Dep Prov Muni Loc Reci NumMesa
{txt}
{com}. duplicates drop

{p 0 4}{txt}Duplicates in terms of {txt} all variables{p_end}

(0 observations are duplicates)

{com}. 
. * Merge 2016 electoral data
. merge 1:1 NumMesa using `merge_2019_2016'
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}           1,507
{txt}{col 9}from master{col 30}{res}           1,507{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}          33,048{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge
{txt}
{com}. 
. * Clean up strings in order to merge on names
. gen str Reci2 = regexs(1) if regexm(Reci, "^(.+)-")
{txt}(33,504 missing values generated)

{com}. gen str Reci3 = regexs(1) if regexm(Reci2, "^(.+)-")
{txt}(34,318 missing values generated)

{com}. gen reci = Reci3 if Reci3 != ""
{txt}(34,318 missing values generated)

{com}. replace reci = Reci2 if Reci2 != "" & Reci3 == ""
{txt}variable {bf}reci{sf} was {bf}{res}str36{sf}{txt} now {bf}{res}str40{sf}
{txt}(814 real changes made)

{com}. replace reci = Reci if reci == ""
{txt}variable {bf}reci{sf} was {bf}{res}str40{sf}{txt} now {bf}{res}str73{sf}
{txt}(33,504 real changes made)

{com}. drop Reci2 Reci3 
{txt}
{com}. 
. superclean_basic Dep Prov Muni Loc reci
{txt}(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(4 real changes made)
(7 real changes made)
(2,367 real changes made)
(0 real changes made)
(1 real change made)
(93 real changes made)
(0 real changes made)
(9 real changes made)
(0 real changes made)
(5 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(5 real changes made)
(34,555 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(322 real changes made)
(352 real changes made)
(895 real changes made)
(46 real changes made)
(65 real changes made)
(17 real changes made)
(5,822 real changes made)
(4 real changes made)
(38 real changes made)
(0 real changes made)
(4 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(74 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(34,555 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(164 real changes made)
(393 real changes made)
(1,582 real changes made)
(534 real changes made)
(50 real changes made)
(3,117 real changes made)
(4 real changes made)
(257 real changes made)
(0 real changes made)
(27 real changes made)
(0 real changes made)
(0 real changes made)
(280 real changes made)
(280 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(23 real changes made)
(34,555 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(63 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(64 real changes made)
(204 real changes made)
(556 real changes made)
(1,142 real changes made)
(528 real changes made)
(57 real changes made)
(3,516 real changes made)
(0 real changes made)
(429 real changes made)
(0 real changes made)
(106 real changes made)
(0 real changes made)
(0 real changes made)
(1,026 real changes made)
(1,026 real changes made)
(26 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(53 real changes made)
(34,555 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(49 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(191 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(19 real changes made)
(287 real changes made)
(382 real changes made)
(374 real changes made)
(435 real changes made)
(195 real changes made)
(1,124 real changes made)
(14 real changes made)
(20,556 real changes made)
(7 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(1,207 real changes made)
(1,192 real changes made)
(11 real changes made)
(867 real changes made)
(0 real changes made)
(0 real changes made)
(940 real changes made)
(34,555 real changes made)

{com}. 
. rename Dep depto 
{res}{txt}
{com}. rename Prov prov
{res}{txt}
{com}. rename Muni mpio
{res}{txt}
{com}. rename Loc loc 
{res}{txt}
{com}. rename Reci Reci_Original
{res}{txt}
{com}. 
. replace reci = subinstr(reci,"ue ","",.)
{txt}(6,102 real changes made)

{com}. replace reci = subinstr(reci,"u e ","",.)
{txt}(1,744 real changes made)

{com}. replace reci = trim(reci)
{txt}(0 real changes made)

{com}. replace reci = itrim(reci)
{txt}(0 real changes made)

{com}. replace loc = subinstr(loc, `"""', "", .)
{txt}(0 real changes made)

{com}. compress
  {txt}variable {bf}depto{sf} was {bf}{res}str22{sf}{txt} now {bf}{res}str20{sf}
  {txt}variable {bf}prov{sf} was {bf}{res}str28{sf}{txt} now {bf}{res}str26{sf}
  {txt}variable {bf}mpio{sf} was {bf}{res}str41{sf}{txt} now {bf}{res}str37{sf}
  {txt}variable {bf}reci{sf} was {bf}{res}str73{sf}{txt} now {bf}{res}str68{sf}
{txt}  (449,215 bytes saved)

{com}. 
. * Merge student's data (recincto level)
. merge m:1 depto prov mpio loc reci using `students_data'
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}           1,562
{txt}{col 9}from master{col 30}{res}           1,558{txt}  (_merge==1)
{col 9}from using{col 30}{res}               4{txt}  (_merge==2)

{col 5}matched{col 30}{res}          32,997{txt}  (_merge==3)
{col 5}{hline 41}

{com}.         /* NOTE: Of 33,048 mesas in the electoral data IN BOLIVIA,
>                  32,997 are matched to the student's data, while
>                          51 are not matched. The other unmatched mesas
>                          are outside of Bolivia and excluded from the 
>                          analysis that includes covariates.*/
. su _m if _m == 2

{txt}    Variable {c |}        Obs        Mean    Std. Dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 6}_merge {c |}{res}          4           2           0          2          2
{txt}
{com}. assert `r(N)' == 4                       
{txt}
{com}. drop if _m == 2                  
{txt}(4 observations deleted)

{com}. drop _m
{txt}
{com}. 
. * Merge municipio centroid coordinates (municipio level)
. merge m:1 depto prov mpio using `coordinates'
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}           1,596
{txt}{col 9}from master{col 30}{res}           1,594{txt}  (_merge==1)
{col 9}from using{col 30}{res}               2{txt}  (_merge==2)

{col 5}matched{col 30}{res}          32,961{txt}  (_merge==3)
{col 5}{hline 41}

{com}. su _m if _m == 2

{txt}    Variable {c |}        Obs        Mean    Std. Dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 6}_merge {c |}{res}          2           2           0          2          2
{txt}
{com}. assert `r(N)' == 2 /* NOTE, these two do not have mpio names and cannot be merged */
{txt}
{com}. drop if _m == 2
{txt}(2 observations deleted)

{com}. drop _m
{txt}
{com}. 
. * Merge census data (municipio level)
. do "codes/auxiliary_programs/2_data_municipio_names.do"
{txt}
{com}. * This file is called within 1_Data_part2_covariates.do
. * The following lines of code were generated based on a fuzzy merge that
. * we then checked and revised by hand
. 
. replace prov = "jose ballivian" if prov == "general jose ballivian" & depto == "beni"
{txt}(225 real changes made)

{com}. replace prov = "esteban arce" if prov == "esteban arze" & depto == "cochabamba"
{txt}(108 real changes made)

{com}. replace prov = "jose manuel pando" if prov == "general jose manuel pando" & depto == "la paz"
{txt}(18 real changes made)

{com}. replace prov = "bernardino bilbao rioja" if prov == "general bernardino bilbao" & depto == "potosi"
{txt}(26 real changes made)

{com}. replace prov = "sur chichas" if prov == "sud chichas" & depto == "potosi"
{txt}(183 real changes made)

{com}. replace prov = "sur lipez" if prov == "sud lipez" & depto == "potosi"
{txt}(24 real changes made)

{com}. replace prov = "obispo santiestevan" if prov == "obispo santisteban" & depto == "santa cruz"
{txt}(569 real changes made)

{com}. replace prov = "aniceto arce" if prov == "arce" & depto == "tarija"
{txt}(203 real changes made)

{com}. replace prov = "burnet oconnor" if prov == "o connor" & depto == "tarija"
{txt}(74 real changes made)

{com}.  
. replace mpio = "santiago de andamarca" if mpio=="andamarca"
{txt}(13 real changes made)

{com}. replace mpio = "sica sica" if mpio=="sicasica"
{txt}(64 real changes made)

{com}. replace mpio = "raqay pampa" if mpio=="raqaypampa"
{txt}(18 real changes made)

{com}. replace mpio = "moro moro" if mpio=="moromoro"
{txt}(11 real changes made)

{com}. replace mpio = "sipe sipe" if mpio=="sipesipe"
{txt}(154 real changes made)

{com}. replace mpio = "postrer valle" if mpio=="postrervalle"
{txt}(9 real changes made)

{com}. replace mpio = "san pedro de curahuara de carangas" if mpio=="san pedro de curahuara"
{txt}(21 real changes made)

{com}. replace mpio = "cuchumuela" if mpio=="villa gualberto villarroel"
{txt}(5 real changes made)

{com}. replace mpio = "san pedro cuarahuara" if mpio == "san pedro de curahuara de carangas" & depto == "la paz"
{txt}(21 real changes made)

{com}. replace mpio = "ascension de guarayos" if mpio == "ascencion de guarayos" & depto == "santa cruz"
{txt}(75 real changes made)

{com}. replace mpio = "sopachuy" if mpio == "sopachui" & depto == "chuquisaca"
{txt}(18 real changes made)

{com}. replace mpio = "jesus de machaca" if mpio == "jesus de machaka" & depto == "la paz"
{txt}(33 real changes made)

{com}. replace mpio = "vitichi" if mpio == "vitiche" & depto == "potosi"
{txt}(26 real changes made)

{com}. replace mpio = "salinas de garcia mendoza" if mpio == "salinas de garci mendoza" & depto == "oruro"
{txt}(26 real changes made)

{com}. replace mpio = "toko" if mpio == "toco" & depto == "cochabamba"
{txt}(18 real changes made)

{com}. replace mpio = "puerto gonzales moreno" if mpio == "puerto gonzalo moreno" & depto == "pando"
{txt}(18 real changes made)

{com}. replace mpio = "villa desacaca" if mpio == "sacaca" & depto == "potosi"
{txt}(47 real changes made)

{com}. replace mpio = "yunguyo de litoral" if mpio == "yunguyo del litoral" & depto == "oruro"
{txt}(1 real change made)

{com}. replace mpio = "choque cota" if mpio == "choquecota" & depto == "oruro"
{txt}(4 real changes made)

{com}. replace mpio = "gral saavedra" if mpio == "general saavedra" & depto == "santa cruz"
{txt}(43 real changes made)

{com}. replace mpio = "villamontes" if mpio == "villa montes" & depto == "tarija"
{txt}(152 real changes made)

{com}. replace mpio = "san josede chiquitos" if mpio == "san jose" & depto == "santa cruz"
{txt}(61 real changes made)

{com}. replace mpio = "la paz" if mpio == "nuestra senora de la paz" & depto == "la paz"
{txt}(2,993 real changes made)

{com}. replace mpio = "quillacas" if mpio == "santuario de quillacas" & depto == "oruro"
{txt}(10 real changes made)

{com}. replace mpio = "puna" if mpio == "puna villa talavera" & depto == "potosi"
{txt}(60 real changes made)

{com}. replace mpio = "villa alcala" if mpio == "alcala" & depto == "chuquisaca"
{txt}(8 real changes made)

{com}. replace mpio = "pto carabuco" if mpio == "puerto mayor de carabuco" & depto == "la paz"
{txt}(36 real changes made)

{com}. replace mpio = "independencia" if mpio == "ayopaya villa de independencia" & depto == "cochabamba"
{txt}(57 real changes made)

{com}. replace mpio = "rurrenabaque" if mpio == "puerto menor de rurrenabaque" & depto == "beni"
{txt}(56 real changes made)

{com}. replace mpio = "san benito" if mpio == "san benito villa jose quintin mendoza" & depto == "cochabamba"
{txt}(45 real changes made)

{com}. replace mpio = "san juan de yapacani" if mpio == "san juan" & depto == "santa cruz"
{txt}(24 real changes made)

{com}. replace mpio = "soracachi" if mpio == "paria soracachi" & depto == "oruro"
{txt}(48 real changes made)

{com}. replace mpio = "chuquihuta" if mpio == "chuquihuta ayllu jucumani" & depto == "potosi"
{txt}(17 real changes made)

{com}. replace mpio = "ancoraimes" if mpio == "villa ancoraimes" & depto == "la paz"
{txt}(35 real changes made)

{com}. replace mpio = "santa ana de yacuma" if mpio == "santa ana" & depto == "beni"
{txt}(45 real changes made)

{com}. replace mpio = "villa san lorenzo" if mpio == "san lorenzo" & depto == "tarija"
{txt}(92 real changes made)

{com}. replace mpio = "san miguel de velasco" if mpio == "san miguel" & depto == "santa cruz"
{txt}(35 real changes made)

{com}. replace mpio = "san pablo de lipez" if mpio == "san pablo" & depto == "potosi"
{txt}(12 real changes made)

{com}. replace mpio = "san ignacio de velasco" if mpio == "san ignacio" & depto == "santa cruz"
{txt}(153 real changes made)

{com}. replace mpio = "santa rosa del sara" if mpio == "santa rosa" & depto == "santa cruz"
{txt}(48 real changes made)

{com}. replace mpio = "villa nueva loma alta" if mpio == "villa nueva" & depto == "pando"
{txt}(8 real changes made)

{com}. replace mpio = "uriondo" if mpio == "uriondo concepcion" & depto == "tarija"
{txt}(55 real changes made)

{com}. replace mpio = "coro coro" if mpio == "corocoro" & depto == "la paz"
{txt}(28 real changes made)

{com}. replace mpio = "san andres de machaca" if mpio == "la marka san andres de machaca" & depto == "la paz"
{txt}(15 real changes made)

{com}. replace mpio = "carmen rivero torrez" if mpio == "el carmen rivero torrez" & depto == "santa cruz"
{txt}(19 real changes made)

{com}. replace mpio = "icla" if mpio == "villa ricardo mugia icla" & depto == "chuquisaca"
{txt}(22 real changes made)

{com}. replace mpio = "callapa" if mpio == "santiago de callapa" & depto == "la paz"
{txt}(18 real changes made)

{com}. replace mpio = "guaqui" if mpio == "puerto mayor de guaqui" & depto == "la paz"
{txt}(22 real changes made)

{com}. replace mpio = "huari" if mpio == "santiago de huari" & depto == "oruro"
{txt}(30 real changes made)

{com}. replace mpio = "san pedro de totora" if mpio == "totora" & depto == "oruro"
{txt}(17 real changes made)

{com}. replace mpio = "sp de buena vista" if mpio == "san pedro" & depto == "potosi"
{txt}(62 real changes made)

{com}. replace mpio = "muyupampa" if mpio == "villa vaca guzman" & depto == "chuquisaca" /* NOTE: https://es.wikipedia.org/wiki/Villa_Vaca_Guzm%C3%A1n */
{txt}(31 real changes made)

{com}. 
{txt}end of do-file

{com}. merge m:1 depto prov mpio using `census2012_municipal' 
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}           1,525
{txt}{col 9}from master{col 30}{res}           1,525{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}          33,030{txt}  (_merge==3)
{col 5}{hline 41}

{com}. su _m if _m == 2

{txt}    Variable {c |}        Obs        Mean    Std. Dev.       Min        Max
{hline 13}{c +}{hline 57}
{space 6}_merge {c |}{res}          0
{txt}
{com}. assert `r(N)' == 0
{txt}
{com}. drop _m
{txt}
{com}. 
. *-------------------------------------------------------------------*
. * 5. Constructing control variables                                                                 *
. *-------------------------------------------------------------------*
. 
. * Replacing some missing values manually
. *---------------------------------------
. * Population
. replace poblacion = 14589 if ///
>         depto == "La Paz" & prov == "Camacho" & mpio == "Puerto Mayor de Carabuco"
{txt}(0 real changes made)

{com}. 
. replace poblacion = 10748 if ///
>         depto == "Chuquisaca" & prov == "Luis Calvo" & ///
>         mpio == "Villa Vaca Guzmán" //Municipality also known as Muyupampa
{txt}(0 real changes made)

{com}. 
. replace poblacion = 7344 if ///
>         depto == "Cochabamba" & prov == "Mizque" & ///
>         mpio == "Raqaypampa" /*  Indigenous territory, doesn't appear in the Census. 
>                                                          Population extracted from: 
>                                                          https://www.raqaypampa.gob.bo/territorio-y-division-politico-administrativa/   
>                                                          */
{txt}(0 real changes made)

{com}.                                                          
. replace poblacion = 28922 if ///
>         depto == "Santa Cruz" & prov == "Chiquitos" & mpio == "San José"       
{txt}(0 real changes made)

{com}. 
. * Distance to capital of department
. rename coordx longitud
{res}{txt}
{com}. rename coordy latitud
{res}{txt}
{com}. replace latitud = -18.189008 if ///
>         depto == "Cochabamba" & prov == "Mizque" & mpio == "Raqaypampa"
{txt}(0 real changes made)

{com}. replace longitud=-65.381503 if ///
>         depto == "Cochabamba" & prov == "Mizque" & mpio == "Raqaypampa"
{txt}(0 real changes made)

{com}. 
. * Agricultural Labor
. replace agricultural_labor = 74 if ///
>         depto == "La Paz" & prov == "Camacho" & mpio == "Puerto Mayor de Carabuco"
{txt}(0 real changes made)

{com}. 
. replace agricultural_labor = 55.8 if ///
>         depto == "Chuquisaca" & prov == "Luis Calvo" & mpio == "Villa Vaca Guzmán" //Municipality also known as Muyupampa
{txt}(0 real changes made)

{com}. 
. replace agricultural_labor = 39.3 if ///
>         depto == "Santa Cruz" & prov == "Chiquitos" & mpio == "San José"       
{txt}(0 real changes made)

{com}. 
. * Census covariates
. gen analfabetismo = 100 - alfabetismo
{txt}(1,525 missing values generated)

{com}. gen logpop = log(poblacion)
{txt}(1,525 missing values generated)

{com}. 
. * Generating a dummy for capital of department
. gen capital_depto=0 if Pais=="Bolivia"
{txt}(1,507 missing values generated)

{com}. replace capital_depto=1 if (depto=="beni" & mpio=="trinidad") | ///
>         (depto=="chuquisaca" & mpio=="sucre") | ///
>         (depto=="cochabamba" & mpio=="cochabamba") | ///
>         (depto=="la paz" & mpio=="la paz") | ///
>         (depto=="oruro" & mpio=="oruro") | ///
>         (depto=="pando" & mpio=="cobija") | ///
>         (depto=="potosi" & mpio=="potosi") | ///
>         (depto=="santa cruz" & mpio=="santa cruz de la sierra") | ///
>         (depto=="tarija" & mpio=="tarija")
{txt}(14,302 real changes made)

{com}. 
. * Minimum distance to (any) capital of department
. preserve
{txt}
{com}.         keep if Pais=="Bolivia"
{txt}(1,507 observations deleted)

{com}.         keep capital_depto latitud longitud depto mpio
{txt}
{com}.         keep if capital_depto == 1
{txt}(18,746 observations deleted)

{com}.         duplicates drop

{p 0 4}{txt}Duplicates in terms of {txt} all variables{p_end}

(14,293 observations deleted)

{com}.         keep latitud longitud
{txt}
{com}.         gen t = _n
{txt}
{com}.         gen t2 = 1
{txt}
{com}.         reshape wide latitud longitud, i(t2) j(t)
{txt}(note: j = 1 2 3 4 5 6 7 8 9)

Data{col 36}long{col 43}->{col 48}wide
{hline 77}
Number of obs.                 {res}       9   {txt}->{res}       1
{txt}Number of variables            {res}       4   {txt}->{res}      19
{txt}j variable (9 values)                 {res}t   {txt}->   (dropped)
xij variables:
                                {res}latitud   {txt}->   {res}latitud1 latitud2 ... latitud9
                               longitud   {txt}->   {res}longitud1 longitud2 ... longitud9
{txt}{hline 77}

{com}. 
.         tempfile capitals
{txt}
{com}.         save `capitals'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_00000g.tmp saved

{com}. restore
{txt}
{com}. 
. gen t2 = 1
{txt}
{com}. merge m:1 t2 using `capitals'
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}          34,555{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge t2
{txt}
{com}. 
. forvalues k = 1/9 {c -(}
{txt}  2{com}.         geodist latitud longitud latitud`k' longitud`k', generate(dist`k')
{txt}  3{com}.         drop latitud`k' longitud`k'
{txt}  4{com}. {c )-}
{txt}
{com}. egen dist_capital = rowmin(dist1 - dist9)
{txt}(1594 missing values generated)

{com}. drop dist1 - dist9
{txt}
{com}. drop lat* long*
{txt}
{com}. 
. * Media luna
. gen medialuna = (depto == "pando" | depto == "beni" | depto == "santa cruz" | ///
>         depto == "tarija")
{txt}
{com}. 
. * Taking the log of some covariates
. gen ln_aglabor = ln(agricultural_labor)
{txt}(1,525 missing values generated)

{com}. gen ln_density = ln(density)
{txt}(1,558 missing values generated)

{com}. gen ln_dist_capital = ln(1 + dist_capital)
{txt}(1,594 missing values generated)

{com}. 
. * 2016 
.         gen mshare2016=si2016/(si2016+no2016)
{txt}(2,285 missing values generated)

{com}.         gen cshare2016=1-mshare2016
{txt}(2,285 missing values generated)

{com}.         gen margin2016=mshare2016-cshare2016
{txt}(2,285 missing values generated)

{com}.         
. * Drop some variables that we don't use
. drop no2016-dr2016
{txt}
{com}. drop loc CódigoMesa recinto2016
{txt}
{com}. 
. * Saving
. compress
  {txt}variable {bf}capital_depto{sf} was {bf}{res}float{sf}{txt} now {bf}{res}byte{sf}
  {txt}variable {bf}medialuna{sf} was {bf}{res}float{sf}{txt} now {bf}{res}byte{sf}
  {txt}variable {bf}mpio{sf} was {bf}{res}str37{sf}{txt} now {bf}{res}str26{sf}
{txt}  (587,435 bytes saved)

{com}. drop Pais depto prov mpio Reci_Original reci
{txt}
{com}. 
. *--
. 
{txt}end of do-file

{com}.         tempfile covariates_full
{txt}
{com}.         save `covariates_full'
{txt}file C:\Users\Nicolas\AppData\Local\Temp\ST_2420_000008.tmp saved

{com}. 
.         foreach x in computo_ulttranstrepdate_missingsatmunmedian ///
>                 computo_ulttranstrepdate_nomissings {c -(}
{txt}  2{com}.                 use "data/outputs//`x'.dta", clear
{txt}  3{com}. 
.                 merge 1:1 NumMesa using `covariates_full'
{txt}  4{com}.                 drop if _merge == 2
{txt}  5{com}.                 drop _merge
{txt}  6{com}. 
.                 compress
{txt}  7{com}.                 saveold "data/outputs//`x'.dta", replace
{txt}  8{com}.         {c )-}
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}               0
{txt}{col 5}matched{col 30}{res}          34,555{txt}  (_merge==3)
{col 5}{hline 41}
(0 observations deleted)
  (0 bytes saved)
(saving in Stata 13 format)
{p 0 6 2}
(FYI, {bf:saveold} has options
{bf:version(12)} and {bf:version(11)} that
write files in older Stata formats)
{p_end}
file data/outputs//computo_ulttranstrepdate_missingsatmunmedian.dta saved
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}             377
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}             377{txt}  (_merge==2)

{col 5}matched{col 30}{res}          34,178{txt}  (_merge==3)
{col 5}{hline 41}
(377 observations deleted)
  (0 bytes saved)
(saving in Stata 13 format)
{p 0 6 2}
(FYI, {bf:saveold} has options
{bf:version(12)} and {bf:version(11)} that
write files in older Stata formats)
{p_end}
file data/outputs//computo_ulttranstrepdate_nomissings.dta saved

{com}. 
. *------------------------------------------------------------------------*
. * 7. Label variables + Sample data (if specified above)                  *
. *------------------------------------------------------------------------*
.         # delimit ;
{txt}delimiter now ;
{com}.                 global datasets "computo_ulttranstrepdate_missingsatmunmedian
>                         computo_ulttranstrepdate_nomissings
>                         computo_verificadortrepdate_missingsatthend
>                         computo_verificadortrepdate_nomissings
>                         computo_verificadortrepdate_nomissings_oasorder";
{txt}
{com}.         # delimit cr
{txt}delimiter now cr
{com}. 
.         * Label variables; sampling if the user specified this option above
.         foreach x of global datasets {c -(}
{txt}  2{com}.                 use "data/outputs//`x'.dta", clear
{txt}  3{com}.                 run "codes/auxiliary_programs/3_VariableLabels.do"
{txt}  4{com}. 
.                 saveold "data/outputs//`x'.dta", replace
{txt}  5{com}.         {c )-}
{txt}(saving in Stata 13 format)
{p 0 6 2}
(FYI, {bf:saveold} has options
{bf:version(12)} and {bf:version(11)} that
write files in older Stata formats)
{p_end}
{p 2 8 2}
note: variable label
"Votes for Unidad Cívica Solidaridad"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Votes for Partido Demócrata Cristiano"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Votes for Partido de Acción Nacional Boliviano"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Cómputo time stamp"
contains unicode and thus may not display well
in Stata 13.
{p_end}
file data/outputs//computo_ulttranstrepdate_missingsatmunmedian.dta saved
(saving in Stata 13 format)
{p 0 6 2}
(FYI, {bf:saveold} has options
{bf:version(12)} and {bf:version(11)} that
write files in older Stata formats)
{p_end}
{p 2 8 2}
note: variable label
"Votes for Unidad Cívica Solidaridad"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Votes for Partido Demócrata Cristiano"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Votes for Partido de Acción Nacional Boliviano"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Cómputo time stamp"
contains unicode and thus may not display well
in Stata 13.
{p_end}
file data/outputs//computo_ulttranstrepdate_nomissings.dta saved
(saving in Stata 13 format)
{p 0 6 2}
(FYI, {bf:saveold} has options
{bf:version(12)} and {bf:version(11)} that
write files in older Stata formats)
{p_end}
{p 2 8 2}
note: variable label
"Votes for Unidad Cívica Solidaridad"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Votes for Partido Demócrata Cristiano"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Votes for Partido de Acción Nacional Boliviano"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Cómputo time stamp"
contains unicode and thus may not display well
in Stata 13.
{p_end}
file data/outputs//computo_verificadortrepdate_missingsatthend.dta saved
(saving in Stata 13 format)
{p 0 6 2}
(FYI, {bf:saveold} has options
{bf:version(12)} and {bf:version(11)} that
write files in older Stata formats)
{p_end}
{p 2 8 2}
note: variable label
"Votes for Unidad Cívica Solidaridad"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Votes for Partido Demócrata Cristiano"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Votes for Partido de Acción Nacional Boliviano"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Cómputo time stamp"
contains unicode and thus may not display well
in Stata 13.
{p_end}
file data/outputs//computo_verificadortrepdate_nomissings.dta saved
(saving in Stata 13 format)
{p 0 6 2}
(FYI, {bf:saveold} has options
{bf:version(12)} and {bf:version(11)} that
write files in older Stata formats)
{p_end}
{p 2 8 2}
note: variable label
"Votes for Unidad Cívica Solidaridad"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Votes for Partido Demócrata Cristiano"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Votes for Partido de Acción Nacional Boliviano"
contains unicode and thus may not display well
in Stata 13.
{p_end}
{p 2 8 2}
note: variable label
"Cómputo time stamp"
contains unicode and thus may not display well
in Stata 13.
{p_end}
file data/outputs//computo_verificadortrepdate_nomissings_oasorder.dta saved

{com}. 
. *------------------------------------------------------------------------------*
. timer off 2
{txt}
{com}. timer list 2
{res}   2:     76.42 /        1 =      76.4190
{txt}
{com}. 
. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}E:\Github\Bolivia\00_replication_files\log-files/1_Data_part1_initialsetup.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}25 Jan 2022, 20:54:45
{txt}{.-}
{smcl}
{txt}{sf}{ul off}